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!

How write data from awk output into different files? 1

Status
Not open for further replies.

gargamel100

Technical User
Oct 25, 2006
31
CZ
Hi all,
usnig this part of code

cat 942prm_200611* | tr ' | ' ' ' > 942sve.txt

awk ' { if(( $10=="30001") && (($22=="34") || ($22=="128") || ($21=="31"))) print $10 "\t" $22 }' 942sve.txt > jacause.txt
awk ' { if(( $10=="30350") && (($22=="31") || ($22=="128") || ($22=="16"))) print $10 "\t" $22 }' 942sve.txt >> jacause.txt
awk ' { if(( $10=="50111") && (($22=="34") || ($22=="128"))) print $10 "\t" $22 }' 942sve.txt >> jacause.txt


I got output like bellow ....

30001 128
30001 128
30001 128
30350 16
30350 16
30350 16
30350 16
30350 31
30350 128
30350 128
30350 31
30350 128
30350 31
30350 16
30350 128
30350 31
30350 31

first column means telephne number and second column menas specific cause for that number. Now I need to implement additional script ( or inside this one ) that will make possible to for example number 30350 select all causes to different files. I need to make output like
in file 30350_128.txt should be

30350 128
30350 128
30350 128

in file 30350_31.txt

30350 31
30350 31

in file 30350_16.txt

30350 16
30350 16
30350 16
30350 16

For number 30001 I need make the same
for example 30001_128.txt

30001 128
30001 128
30001 128

( there is no other causes for this number, just this one )

and for every differnt number in column one write data for specific cause in column 2 into differen file like in example above.

I am hoping that someone know how to do this and have time to write, or just send me an hint how to do this... and help me.

I must do it in awk, no other program languages.

Thank you in advance

Regards
Gargamel100
 
A starting point:
awk '{print > $1"_"$2".txt"}' jacause.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thank you very much, with this single line you saved me a lot of nervs and time thank you again

Regards
 
Hi

Some time ago I read it here on Tek-Tips, that such [tt]awk[/tt] script, which writes in a lot of files without closing the previously opened ones, will crash if uses all available file handles. And I just run into this problem earlier this week.

Just as a hint, but probably you will not need it.

Feherke.
 
that's right. E.g. Solaris' awk/nawk has max open output files set to '10'. Therefore, it might be a good idea to 'close(outputFile)' every time do a prit/printf to a file.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top