Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I did, but there's ALOT to look through... I tried:
sort -n numbers | sed -n 1p numbers > largest
sort -n numbers | sed -n 1p > largest
Neither worked... I'll keep trying!
Out of curiosity: what WERE the results of those commands
of yours, what did you get in the file 'largest'? I would
have expected the last one to work.
Out of curiosity: what WERE the results of those commands
of yours, what did you get in the file 'largest'? I would
have expected the last one to work.
Cheers,
Tink
Well the program won't allow me to tinker with its insides (it's basically a program where you write in the answer and won't let you do anything else). Anyway I made a file to try this out myself, within numbers I had:
8
32
21
31
500
43
And when I used 'sort -n numbers | sed -n 1p > largest' it ended up being exactly the same.
When I used 'sort -n numbers | sed -n 1p > largest' the result in 'numbers' was 8. So it seems that my sort command isn't working, which makes no sense to me as it looks fine. Any idea on what's wrong?
Quote:
Originally Posted by johnsfine
I didn't think it needed further explanation.
Sort so the largest value is the last line. Pipe that to tail to copy just the last line to the destination file.
Sadly it seems I have an inherit need to make things as complicated as possible, I'll try that out.
I feel like I have stepped into the twilight zone.....
sort -n puts the largest value last. So sed '1p' will give you the smallest value. Is your system somehow different???
EDIT---maybe "sort" is aliased to something else????
Nuh .. it's all good, we're both blind :}
It does exactly what we tell it to. Sort gives him 500 as the
last, but with sed we print the first line only, which will be
the smallest number - 8 in his case. The "trick" would be to
actually do the $p rather than 1p ;}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.