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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bucket Lines with same pattern to one file.....

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
HI All,

For example I have a "file" which contains the following,

1 CAT 34
2 CAT 33
3 CAT 88
4 DOG 90
5 DOG 12
6 PIG 34
7 PIG 33
8 PIG 25
9 COW 44
10 COW 45
11 ANT 23
12 ANT 33

Does anyone know how I can bucket the lines containing CAT and save it to one file named cat.txt, the same goes for DOG in dog.txt and for PIG in pig.txt?

I used bigoldbulldog's code below....

#! /usr/bin/awk -f
$2 != "" { print > tolower($2) ".txt" }

but an error message appears which says:
awk : too many output files...

Does anyone know how I can still use the above script to be incorporated on a file with more than 10 entries???

Thanks!
-CGLY
 

awk '{c=tolower($2);print $0 >> c".txt"}' file

remember to remove the files from the prvious run before you process the file again.(it just keeps appending to the files)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top