题目大意:给一个多行的文件,让你写一段shell脚本把文件的第10行输出来。
方法一:
# Read from the file file.txt and output the tenth line to stdout.
count=0
while read line && [ $count -le 10 ]
do
count=$[$count+1]
if [ $count -eq 10 ]
then
echo $line
exit
fi
done < 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
Shell脚本读取文件特定行
153

被折叠的 条评论
为什么被折叠?



