输出第5行的内容

输出第5行的内容

编写一个bash脚本以输出一个文本文件nowcoder.txt中第5行的内容。

示例:
假设 nowcoder.txt 内容如下:

1
2
3
4
5
6
7
welcome
to
nowcoder
this
is
shell
code

你的脚本应当输出:
is。

题解

1
2
3
4
5
6
7
8
# 方法 1
sed -n '5p' nowcoder.txt

# 方法 2
head -n 5 nowcoder.txt | tail -n 1

# 方法 3
awk '{ if(NR==5) {print($0)} }' nowcoder.txt

(本文完)

在线题库


输出第5行的内容
https://maojun.xyz/blog/2023/11/输出第5行的内容.html
作者
毛 俊
发布于
2023年11月5日
许可协议