[英]how to print out the data at the certain line using bash script?
我有一个100k行的txt文件。 如果我想知道第24356行的数据是什么,该如何在命令行中进行操作?
您可以使用awk
获得特定行:
awk 'NR==24356{print;exit}' input_file
这将打印该行并在记录号NR
是您想要的后立即退出,否则将无济于事。 exit
是为了确保您不会在感兴趣的行之后不必要地处理行。
例如,请参阅以下记录:
pax> cat qq.sh
while read line
do
echo "Reading within the loop: [$line]"
echo -n "What do you want to say? "
read -u 3 something
echo "You input: [$something]"
done 3<&0 <qq.sh
pax> awk 'NR==2{print;exit}' qq.sh
do
pax> awk 'NR==3{print;exit}' qq.sh
echo "Reading within the loop: [$line]"
sed
可以打印指定的行范围,因此在这种情况下将被sed -n 24356,24356p $FILE
尝试这个:
cat filename | head -24356 | tail -1
使用的命令应该在每个* nix系统上都可用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.