Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-14-2011, 05:24 PM   #1
LQ Newbie
Registered: Nov 2011
Posts: 5

Rep: Reputation: Disabled
Question Cut Rows

How do I cut rows out of my listing?

Here is my current code:

ls-l1S | cut d f8 | cut -d' '

I need the largest file to be the only one remaining, (ie: cutting all other files/listings out of the listing)

Currently it has


It needs to just display the first one (CIS350)

Old 11-14-2011, 07:14 PM   #2
Nominal Animal
Senior Member
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 947Reputation: 947Reputation: 947Reputation: 947Reputation: 947Reputation: 947Reputation: 947Reputation: 947
See man 1 head. To output only the first line, and skip the others, use head -n 1
Old 11-14-2011, 08:24 PM   #3
LQ Newbie
Registered: Nov 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
It worked :-) thanks!
Old 11-15-2011, 12:47 PM   #4
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,842

Rep: Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003
You really should keep follow-up questions in the same thread as the original. Start a new thread when you have a completely new topic to discuss.

I just posted a reply in your last thread about this:

Also, please use [code][/code] tags around your code, to preserve formatting and to improve readability. Thanks.

Anyway, another trick is to use the read built-in.

read file < <( ls 1S )
echo "$file"
The above code uses bash's process substitution. It would have to be modified for other shells.

Note also that this assumes that the filename you want sits on the first line. As the link I gave in the other thread points out, newlines are legal characters in *nix file names, so it is possible for it to only grab a partial file name. The technique I posted before doesn't have that problem.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
`ls -ltra | cut -f3` How would you cut? frenchn00b Linux - Newbie 11 06-13-2011 02:54 AM
help with cut command using find. Cut last 8 characters leaving the rest ncsuapex Programming 4 09-16-2009 08:55 PM
Compare two fields on consecutive rows and print the two rows aditi_borkar Linux - Newbie 3 04-09-2009 05:49 AM
How to use command grep,cut,awk to cut a data from a file? hocheetiong Linux - Newbie 7 09-11-2008 07:16 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:50 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration