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!

Split File

Status
Not open for further replies.

clemhoff

Technical User
Jul 10, 2007
19
FR

Hello All,

I would like to split a big "pipe" delimited file in as many files as there are columns. The number of columns being undefined, how to make so that each column header acts as the output file name?

Sample IN
header1|header2|...|headern
11111|txt1|...|alphanum_n1
22222|txt2|...|alphanum_n2
33333|txt3|...|alphanum_n3

Sample OUT
file #1 name -> header1.txt
11111
22222
33333

...
file #n name -> headern.txt
alphanum_n1
alphanum_n2
alphanum_n3


Thank you in advance
Regards
Clement

 
awk -F'|' '
NR==1{for(i=1;i<=NF;++i)out=$i".txt";next}
{for(i=1;i<=NF;++i)print $i>out}
' /path/to/input

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

Part and Inventory Search

Sponsor

Back
Top