且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何打印每第4列至第n列,并从第(n + 1)列到最后用awk?

更新时间:2022-12-10 18:12:41

 的awk'{为(i = 3; I< = 51; I + = 4)的printf%S, $ I;对于(I = 52; I< = 119;我++){printf的%S,$ I};打印}'文件

I have a dataset with 119 columns separated by a space and like to select columns (3,7,11,...,47,51), (52,53,54,...,118,119) and print them out to another file. How can I do this using awk?

Input file 

c1 c2 c3...c119

Output file

c3 c7 c11 ... c51 c52 c53 c54 ... c118 c119 

Thanks for your help

awk '{for(i=3;i<=51;i+=4) printf "%s ",$i ;for(i=52;i<=119;i++) {printf "%s ",$i} ;print ""}' file