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

How to generate file from a awk variable

Status
Not open for further replies.

rrs123

MIS
Jun 17, 2009
2
US
Hello,

I have a csv file just like bellow.

"filename1","d1","d2","d3","d4",
"filename1","d1","d2","d3","d4",
"filename1","d1","d2","d3","d4",
"filename2","d1","d2","d3","d4",
"filename2","d1","d2","d3","d4",
"filename2","d1","d2","d3","d4",

What I would like to create two files filename1 and filename2 as follow.

filename1:
"d1","d2","d3","d4",
"d1","d2","d3","d4",
"d1","d2","d3","d4",
filename2:
"d1","d2","d3","d4",
"d1","d2","d3","d4",
"d1","d2","d3","d4",

How could I do ut using awk?

Thanks in advance

RS
 
Code:
awk -F'"' '{out=$2;x=$0;sub(/[^,]*,/,"",x);print x>out}' /path/to/input.csv

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top