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.
Not sure why you would think that sorting would work? You will not eliminate any of the data not required.
Your original question asked for the min & max per line, whilst sorting in this way would work on a column. Please show your suggested output for your current input data?
The addition of the awk in your second script will yield no difference whatsoever as you are simply printing the whole line
I'm sure you can do this in bash, but for these kind of things I tend to use Python:
Code:
$ ./min_max.py
Max 9111, Min 1320
Max 6548, Min 76
Max 6428, Min 567
Max 8625, Min 8625
Max 9922, Min 1241
Max 9727, Min 3553
Max 8573, Min 3945
Max 1273, Min 1273
Max 8719, Min 1076
Max 7458, Min 1637
Max 9612, Min 1399
Max 6911, Min 2235
Max 504, Min 504
Max 2770, Min 396
Max 6900, Min 151
Max 8695, Min 2258
Max 4006, Min 2630
Max 7255, Min 726
Max 2214, Min 1866
Max 7491, Min 193
Max 8463, Min 916
Max 9557, Min 8166
Max 6813, Min 2959
PS. I am sure there is a killer oneliner in awk just waiting to be done by grail... DS.
PSS. My python script is just 8 lines long, so it's really quick and easy once you know what to do. DSS.
The bash would look something similar.
Loop through the file, for each line slurp the line and break it into a list words, find the smallest and largest words in the list, and write out your answer for that line.
I am not good in bash,I'm just started learning, so not specially
But here is a template:
Quote:
Originally Posted by wpeckham
Loop through the file, for each line slurp the line and break it into a list words, find the smallest and largest words in the list, and write out your answer for that line.
Also, that is the approach I took in my Python script. You can use the same approach with Bash.
First things first, do you know how to read a file, line by line in Bash? If not: https://is.gd/A6RKTL
My suggestion is that you start there, and get back with your follow-up questions.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.