|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Grouping or appending the lines in a file through Unix
Hi, I am looking for a way to Group the Lines in a file.. Basically My file structure is something like this Code:
A 1 100 abc def A 1 200 abc def A 1 300 abc def A 2 100 pqr def A 2 200 pqr def A 2 300 pqr def A 1 100 abc def A 1 200 xyz def A 1 300 xyz def I need it as shown below, Its Just to Group All records with 1 in the 2nd field Code:
A 1 100 abc def A 1 200 abc def A 1 300 abc def A 1 100 abc def A 1 200 xyz def A 1 300 xyz def A 2 100 pqr def A 2 200 pqr def A 2 300 pqr def It would be really great if you can tell me a logic to regroup and remove certain unwanted or duplicate record in the 2nd occurence.. If you see above you can find that "A 1 100 abc def " is repeated twice... I would neeed an output like this Code:
A 1 100 abc def A 1 200 abc def A 1 300 abc def A 1 200 xyz def A 1 300 xyz def A 2 100 pqr def A 2 200 pqr def A 2 300 pqr def Let me know if someone has idea on these lines Last edited by joeyg; 05-30-2012 at 01:32 PM.. Reason: Please wrap data and scripts/commands with CodeTags. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Seems a sort command would get you started.
Are you truly trying to sort on columns 2, then 4, and then 3? |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
you could use for your sample data Code:
sort -k1,1 -k2,2 -k4,4 infile but ideally you should use Code:
sort -k1,1 -k4,4 -k2,2 infile |
|
#4
|
|||
|
|||
|
Actually joeyg, I just gave a sample.. My file is something similar in these lines but is very big with lot of lines and each line having lot of info... But when i used sort command, The output was getting jumbled... Code:
A 1 100 abc def A 1 100 abc def A 1 200 abc def A 1 200 xyz def A 1 300 abc def A 1 300 xyz def A 2 100 pqr def A 2 200 pqr def A 2 300 pqr def But this is not what i am expecting Last edited by Scrutinizer; 05-30-2012 at 04:32 PM.. Reason: code tags |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
post what command you are using. Did you tried what is suggested in post #3
|
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
expecting this .. Code:
$ nawk '!x[$2$3]++' infile |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Use something like Code:
sort -k1,1 -k2,2 -k4,4 tt | uniq |
| Sponsored Links | ||
|
![]() |
| Tags |
| append, group, reorder, sort, uniq |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Grouping or appending the lines in a file through Unix | mkandula1983 | Shell Programming and Scripting | 1 | 05-30-2012 01:34 PM |
| appending lines to a file dynamically | Ananthdoss | Shell Programming and Scripting | 2 | 12-09-2011 07:41 AM |
| File splitting and grouping using unix script | nandhan11891 | Shell Programming and Scripting | 4 | 04-20-2010 09:49 PM |
| grouping records in a file in unix | trichyselva | Shell Programming and Scripting | 8 | 09-11-2009 03:31 AM |
| need help appending lines/combining lines within a file... | mr_manny | Shell Programming and Scripting | 2 | 01-06-2006 05:45 PM |
|
|