bash命令在特定行号范围内打印列 [英] bash command to print column at specific range of line numbers
本文介绍了bash命令在特定行号范围内打印列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在第5到5 + Y行中获取X列中的值.我猜想有一种使用awk
进行此操作的快速方法.怎么做?
I'm trying to get the values in column X at lines 5 to 5 + Y. I'm guessing there's a quick way to do this with awk
. How is this done?
推荐答案
我认为这对您有效,未经测试:
I think this will work for you, untested:
awk 'NR >= 5 && NR <= 5 + Y { print $X }' file.txt
很明显,用X
和Y
代替一些实际值.
Obviously, substitute X
and Y
for some real values.
如果X
和Y
是shell变量:
If X
and Y
are shell variables:
awk -v column="$X" -v range="$Y" 'NR >= 5 && NR <= 5 + range { print $column }' file.txt
这篇关于bash命令在特定行号范围内打印列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文