LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 11-14-2011, 05:24 PM   #1
lainey
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

CIS350
MyNetworkingClass
MyNetworkingClass^C
MyNetworking
MyNetworking^C

It needs to just display the first one (CIS350)

Thanks!
 
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: 946Reputation: 946Reputation: 946Reputation: 946Reputation: 946Reputation: 946Reputation: 946Reputation: 946
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
lainey
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 sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959
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:

http://www.linuxquestions.org/questi...e-size-913510/

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.

Code:
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.
 
  


Reply


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


All times are GMT -5. The time now is 11:13 AM.

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