什么-s选项在GNU sed中意味着什么?

时间:2016-08-29 08:28:36

标签: bash sed

我已阅读-s选项的sed手册。它说:

  

-s   --separate默认情况下,sed会将命令行中指定的文件视为单个连续长流。这个GNU sed   扩展允许用户将它们视为单独的文件:范围   地址(例如'/ abc /,/ def /')不允许跨越几个   文件,行号相对于每个文件的开头,$ refer   到每个文件的最后一行,以及从R命令调用的文件   在每个文件的开头重新编写。

在同一个

中添加-s和no -s
[root@kvm ~]# cat 1 |sed -s   -n '/1/p'
12345a6789a99999a
12345a6789a99999b

[root@kvm ~]# cat 1 |sed     -n '/1/p'
12345a6789a99999a
12345a6789a99999b

1 file is 
cat 1
12345a6789a99999a
12345a6789a99999b

如何使用-s?

1 个答案:

答案 0 :(得分:8)

只有您提供sed个多个文件才会很重要。

如果您未指定-s标志,sed将表现为文件内容已在单个流中连接:

echo "123
456
789" > file1
echo "abc
def
ghi" > file2

# input files are considered a single stream of 6 lines, whose second to fourth are printed
sed -n '2,4 p' file1 file2 

456    # stream 1, line 2
789    # stream 1, line 3
abc    # stream 1, line 4


# there are two distinct streams of 3 lines the 2nd and 3rd of each are printed
sed -ns '2,4 p' file1 file2

456    # stream 1, line 2
789    # stream 1, line 3
def    # stream 2, line 2
ghi    # stream 2, line 3
相关问题