Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-30-2012
Registered User
 
Join Date: May 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
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

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 1s in the 2nd field

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

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
Sponsored Links
    #2  
Old 05-30-2012
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Location: Out running a Marathon.
Posts: 2,194
Thanks: 48
Thanked 128 Times in 120 Posts
Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.
Sponsored Links
Closed Thread

Tags
append, group, reorder, sort, uniq

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 UNIX for Dummies Questions & Answers 6 05-31-2012 04:23 AM
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



All times are GMT -4. The time now is 07:30 PM.