我已阅读sed该-s选项的手册.它说:
-s --separate默认情况下,sed会将命令行中指定的文件视为单个连续长流.这个GNU sed扩展允许用户将它们视为单独的文件:范围地址(例如'/ abc /,/ def /')不允许跨越多个文件,行号相对于每个文件的开头,$ refer到每个文件的最后一行,从R命令调用的文件在每个文件的开头重绕.
在-s中添加-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
Run Code Online (Sandbox Code Playgroud)
如何使用-s?
只有你提供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
Run Code Online (Sandbox Code Playgroud)