Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grouping data

Status
Not open for further replies.

sandeepmur

Programmer
Dec 14, 2003
295
PT
Hi,

I have a file with 5 columns of data in it and I need to group the data according to the 5th column not really sort..

The data in my 5th column reads something like:

SAP
SAP
SBL
TTT
SBL
SBL
SBL
SAP

I want to obtain all the data but ordering them according to the 5th column..

I tried using sort in shell but not really giving me what i need...

any suggestions ?

thnx
 
Please post the structure of your file and what you've tried with the sort command.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
The file structure is:

adb asdfa bvv.tra SBL
adb adsgh vbv.tra SBL
adb yertert dfa.tra TIP
adb bvxxcbcxb sdfasd.tra SBL|ttt
adb ertwert adf.tra NL
adb jfdjhsg werw.tra SBL
adb gfssfss gnf.tra NL
adb nxbsfg rewr.tra NL

I need to order all the data to appear as:

adb asdfa bvv.tra SBL
adb adsgh vbv.tra SBL
adb yertert dfa.tra SBL
adb bvxxcbcxb sdfasd.tra SBL|ttt
adb ertwert adf.tra TIP
adb jfdjhsg werw.tra NL
adb gfssfss gnf.tra NL
adb nxbsfg rewr.tra NL

the cmd i am working on :

sort -k 4,4 components.cfg | awk .....

thnx
 
What are the rules for the "sorting" ?
i.e. why is NL after TIP ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
No rules applicable.. The only requirement is that the data be grouped together.. it could be :

TIP, NL , SBL or SBL,TIP,NL and so on...

thnx
 
So the sort command should be OK. What is the problem ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I tried executing the command sort -k 4,4 components.cfg
directly in shell. The cmd seems to be doing something since the file is formatted differently but the data is not being grouped together. not sure why...
 
for ex. I executed the cmd sort -k 4,4 test over a file containing :

adb asdfa bvv.tra SBL
adb adsgh vbv.tra SBL
adb yertert dfa.tra TIP
adb bvxxcbcxb sdfasd.tra SBL|ttt
adb ertwert adf.tra NL
adb jfdjhsg werw.tra SBL
adb gfssfss gnf.tra NL
adb nxbsfg rewr.tra NL

and the OUTPUT I got was something like:

adb asdfa bvv.tra SBL
adb adsgh vbv.tra SBL
adb yertert dfa.tra SBL|ttt
adb bvxxcbcxb sdfasd.tra TIP
adb ertwert adf.tra NL
adb jfdjhsg werw.tra NL
adb gfssfss gnf.tra NL
adb nxbsfg rewr.tra SBL

As you can see the output comes out kinda formatted but not very correctly..
 
No funny character in your file ?
Here what I get with your sample data:
sort -k 4,4 components.cfg
adb ertwert adf.tra NL
adb gfssfss gnf.tra NL
adb nxbsfg rewr.tra NL
adb adsgh vbv.tra SBL
adb asdfa bvv.tra SBL
adb jfdjhsg werw.tra SBL
adb bvxxcbcxb sdfasd.tra SBL|ttt
adb yertert dfa.tra TIP

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
hmm.. u r right bout the sample data.. thing is I am executing the cmd over a large config file which has the fwg structure..

###
## comments

data
<--- blank line
data
<-- blank line
*abc
# comment

executing the cmd over this file is not getting the desired results :(.. can I do this with awk ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top