linux中如果echo结果有多行,如何取某一行?

来源:百度知道 编辑:UC知道 时间:2024/05/04 20:45:58
linux中如果echo结果有多行,如何取某一行?比如echo的结果为
procs -----------memory---------- ---swap-- -----io----
1 0 268 39456 75704 2568204 0 0 20

我如何获取第二行,就是:
1 0 268 39456 75704 2568204 0 0 20
这行?

echo "line1\nline2" | sed -n "2p"

echo "line1\nline2" 就是随便举例

此题用awk是杀鸡用牛刀。
"with awk and sed, you can do anything you want in linux", this is what I heard from my supervisor...