Solved use awk command to separate files

June 13, 2012 at 06:23:58
Specs: SunOS 5.10, Generic_118833-36 sun4u sparc SUNW
The contents below are in one file, and I want a command to put each content in a separate file? Want to use field 4 to do this ...

8|1|0|2|0|653010077770701||


9|1|0|1|0|653010077770978||


See More: use awk command to separate files

Report •

#1
June 13, 2012 at 14:55:39
✔ Best Answer
I'm not certain of your requirements, so I'm assuming your Field Seperator is a pipe symbol and you want to print each line's field 4. I call the new file file4.txt in the current directory:

#!/bin/bash

awk ' BEGIN { FS="|" }
{
if(NR == 1)
   { # build the file names on the first record
   fn="./file4.txt"
   }

print $4 >> fn
} ' datafile.txt


Report •
Related Solutions


Ask Question