Guys,
Can any one tell me how can we cut the columns and move each column in to a separate file using awk?
I have a tab delimited file as shown below,
1213 wattt werree
2345 skhasdjh aasas
I want to output this in to three files named a.txt,b.txt and c.txt
say a.txt contains
1213
2345
and b.txt contains
watt
skhasdjh
and so on..,
Thanks..,
RacerX
2
I'm no Awk guru but wouldn't something like the following work:
awk -F\t '{ print $1 }' ~/Desktop/datafile.txt > ~/Desktop/a.txt
awk -F\t '{ print $2 }' ~/Desktop/datafile.txt > ~/Desktop/b.txt
awk -F\t '{ print $3 }' ~/Desktop/datafile.txt > ~/Desktop/c.txt
BEGIN {
filesN=split("a.txt b.txt c.txt", filesA, " ")
}
{
for(i=1; i <= filesN; i++) {
print $i > filesA
close(filesA)
}
}