File 打印任何UNIX文件的中间行
我必须在没有sed或awk的情况下打印任何文本文件的中间行 例如,下面的file.txt文件:File 打印任何UNIX文件的中间行,file,unix,text,printing,line,File,Unix,Text,Printing,Line,我必须在没有sed或awk的情况下打印任何文本文件的中间行 例如,下面的file.txt文件: line 1 line 2 line 3 line 4 line 5 我需要像这样的东西: $ command -flags file.txt line 3 有命令吗 谢谢。不是最有效的,但在bash中可以工作 使用wc-l计算行数,然后除以2。然后使用tail-n+n | head-n1只打印n第行(其中n从1开始) 请注意,行数为偶数的文件没有单独的“中间行” 我cat-将文件编辑到wc-l,
line 1
line 2
line 3
line 4
line 5
我需要像这样的东西:
$ command -flags file.txt
line 3
有命令吗
谢谢。不是最有效的,但在bash中可以工作 使用
wc-l
计算行数,然后除以2。然后使用tail-n+n | head-n1
只打印n
第行(其中n
从1开始)
请注意,行数为偶数的文件没有单独的“中间行”
我
cat
-将文件编辑到wc-l
,这样它就不会打印文件名。不是最有效的,但在bash中工作
sed -n $(((`cat input.txt| wc -l`/ 2) + 1))p input.txt
使用wc-l
计算行数,然后除以2。然后使用tail-n+n | head-n1
只打印n
第行(其中n
从1开始)
请注意,行数为偶数的文件没有单独的“中间行”
我
cat
-ed文件到wc-l
,这样它就不会打印文件名。cat-input.txt | wc-l
可以替换为wc-l
cat-input.txt
可以替换为wc-l
问题是如何在没有sed
或awk
对吗?问题是没有sed
或awk
怎么做,对吗?
sed -n $(((`cat input.txt| wc -l`/ 2) + 1))p input.txt