LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Cut Rows (https://www.linuxquestions.org/questions/linux-newbie-8/cut-rows-913540/)

lainey 11-14-2011 05:24 PM

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!

Nominal Animal 11-14-2011 07:14 PM

See man 1 head. To output only the first line, and skip the others, use head -n 1

lainey 11-14-2011 08:24 PM

It worked :-) thanks!

David the H. 11-15-2011 12:47 PM

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.


All times are GMT -5. The time now is 04:03 PM.