如何parsingunix中的平面文件中的奇数字段?

我有一个平面文件,我想从所有的行中parsing奇数列。

我对UNIX非常陌生,我接触的方式是这样的

awk 'BEGIN{ FS = OFS = "|" } { for (i=2;i<=NF;i++) { if(i%2==0) { print $i }}}' newProcessFile.txt 

显然它不会产生所需的输出。 我究竟做错了什么 ? 请解释 。

你可以做awk

 awk '{for (i=1;i<=NF;i+=2) printf "%s ",$i;print ""}' file 

它会打印每隔一列。

 cat file one one two one two three one two three four one two three four five one two three four five six 

 awk '{for (i=1;i<=NF;i+=2) printf "%s ",$i;print ""}' file one one one three one three one three five one three five 

与其他分离器:

 cat file one one|two one|two|three one|two|three|four one|two|three|four|five one|two|three|four|five|six 

 awk -F\| '{s="";for (i=1;i<=NF;i+=2) {s=s?s FS $i:$i} print s}' file one one one|three one|three one|three|five one|three|five