![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sorting problem | cool4naren | UNIX for Dummies Questions & Answers | 4 | 07-31-2007 08:28 AM |
| Sorting problem.... | jarod004 | HP-UX | 4 | 06-25-2007 12:42 AM |
| Sorting/Filed Defining/Output problem | TiredOrangeCat | Shell Programming and Scripting | 1 | 02-12-2007 12:41 AM |
| Data arrangement | bobo | UNIX for Dummies Questions & Answers | 6 | 09-21-2006 10:36 AM |
| Problem in sorting the file | vishnu_vaka | Shell Programming and Scripting | 1 | 12-04-2005 11:47 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
sorting/arrangement problem
Hi,
I have the following 'sorting' problem. Given the input file: a s:m:d:8:z:m a p:q:r:23:y:m a p:q:r:1:y:m the output I expect is: a p:q:r:1:y:m s:m:d:8:z:m What happened here is I grouped together lines having the same values for columns 1,2,3,5,6 and selected only the line with the smallest value in the 4th column in every group. I am currently managing this with a small PERL script. Is there a way to do this using shell utilities alone? Regards... |
|
||||
|
Tweaked for my system
Hi,
I made small change to the code posted by Ygor...and that will apply to solution by Aigles too (remember, my problem is reassigning $4 doesnt modify $0). Heres the changed code: awk 'BEGIN{FS=":"}{str=""; for(j=1;j<=NF;++j) str=sprintf("%s%s",str,$j)} (v[str]=="")||(v[str]>$4){v[str]=$4;a[str]=$0}END{for(i in a)print a[i]}' file1 Here are the tweaks: (1) Now I have a new variable "str" - this doesnt have the 4th column values (2) In the condition part, now I check for (v[str]=="") instead of (!v[str]) --- the latter throws an error on my system. Thanks to everyone for the effort.... Regards, Abhishek |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|