Tenth Line

来源:互联网 发布:软件压力测试工具 编辑:程序博客网 时间:2024/05/23 20:09

题目大意:给一个多行的文件,让你写一段shell脚本把文件的第10行输出来。

方法一:

# Read from the file file.txt and output the tenth line to stdout.count=0while read line && [ $count -le 10 ]do    count=$[$count+1]    if [ $count -eq 10 ]    then        echo $line        exit    fidone < file.txt

方法二:

# Read from the file file.txt and output the tenth line to stdout.sed -n '10p' file.txt

方法三:

# Read from the file file.txt and output the tenth line to stdout.awk '{if(NR==10) print $0}' file.txt

方法四:(方法三的简化)

# Read from the file file.txt and output the tenth line to stdout.awk 'NR==10' file.txt


0 0
原创粉丝点击