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!

Awker expert, Arranging Data, Pls help!

Status
Not open for further replies.

hendnov

Technical User
Feb 27, 2006
73
AU
Hi guys, I'm quite new in awk, please help.
Here's the input data :
10 AMM/SGML/
20 AMM/CGM/
30 AMM/DATA/
46 IPC/SGML/
65 IPC/TIFF/
12 SSM/SGML/
21 SWPM/SGML/

I just want to sort out SGML directory first, and then the graphic files which is CGM or TIFF. other directory I don't want to print out.

so, expected output should be :
10 AMM/SGML/
46 IPC/SGML/
12 SSM/SGML/
21 SWPM/SGML/

20 AMM/CGM/
65 IPC/TIFF/

thx guys!
 
A starting point:
awk '
/\/SGML\//{print;next}
/\/(TIFF|CGM)\//{a[i++]=$0}
END{for(j=0;j<i;++j)print a[j]}
' /path/to/input

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

Sorting in that SGML-CGM-TIFF order would be abit more ugly. Really needed ?
Code:
awk -F / '$2~/SGML|CGM|TIFF/{o[$2]=o[$2] $0 "\n"}END{for(i in o)print o[i]}' /input/file
[gray]# or[/gray]
grep -w "SGML\|CGM\|TIFF" /input/file | sort -t / -k 2

Feherke.
 
THX guys, for your quick reply..

one more question, how do I capture each string of line data into one string. here's the example :

line 1 :
10 SGML -> $CAPTURE

line 2 :
20 TIFF -> $CAPTURE

so, after reading second line, at the end $CAPTURE is "10 SGML \n 20 TIFF" instead of "20 TIFF"

I know, if integer we can use $CAPTURE += 10, but for sentence or word how do i do that?

THX GUYS
 
THX GUYS FOR YOUR HELP,
I MADE IT.

CHEERS,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top