顯示具有 awk 標籤的文章。 顯示所有文章
顯示具有 awk 標籤的文章。 顯示所有文章

2011年10月10日 星期一

Split files according to index

 Suppose I have a csv file like this:
27, california , A3
27, vermont, B6
27, ontario, B7
34, kansas, C9
34, washington, A2

How do I split this file into two files according to field1.
file1:
27, california , A3
27, vermont, B6
27, ontario, B7
file2:
34, kansas, C9
34, washington, A2



awk -F"," ' { print > "file"$1 } ' filename

awk command to merge columns from two separate files into single file

> cat file1
one two three
one two three
one two three
one two three

> cat file2
four five six
four five six
four five six
four five six

> pr -m -t -s file1 file2 | gawk '{print $4,$5,$6,$1}'
four five six one
four five six one
four five six one
four five six one