![]() |
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 |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Multiple file needed with certain file_prefix | rauphelhunter | Shell Programming and Scripting | 6 | 05-27-2008 05:26 AM |
| Help Needed : Split one big file to multiple files | monicasgupta | Shell Programming and Scripting | 5 | 03-03-2008 07:09 PM |
| add columns from file to another and sort | kamel.seg | Shell Programming and Scripting | 12 | 12-12-2007 02:39 PM |
| Help needed to sort file | inditopgun | Shell Programming and Scripting | 2 | 09-27-2007 06:40 PM |
| sorting a file with multiple columns | outtacontrol | UNIX for Dummies Questions & Answers | 3 | 07-26-2006 01:51 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Help needed to sort multiple columns in one file
Hi,
I would like to know given that I have 3 columns. Let say I have first 3 columns to do operation and these operation output is printed out each line by line using AWK and associative array.Currently in the output file, I do a sort by -r for the operation output. The problem comes to picture where I have more than one operation to perform on the same 3 columns and hence, different variables array. I would like to sort this when the first and second column value gives me 0 value. my current code is something like:- cat a.txt| awk ` { count[$1]=count[$3]+2; add[$1]=count[$3]+3; } END{ for(i in count){ printf("%d %d\n", count[i], add[i]);} }`|sort -r catsort.txt The above script only sort by "count" array variables. What I desired is to have "add" to sort if $1 and $2 is "0". I thought of duplicate the whole thing again to sort by "add" which i just need to modify the printf to printf("%d %d\n" ,add[i],count[i]) and add the condition of if $1 and $2 is 0.But it doesnt seem to make sense to me as this cause to create more files! Please help! Thanks -Jason |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|