2016-08-29 51 views
2

我已閱讀-s選件的sed手冊。它說:-s選項在GNU sed中意味着什麼?

-s --separate默認情況下,sed會將命令行中指定的文件視爲單個連續的長流。此GNU sed 擴展允許用戶將它們視爲單獨的文件:範圍 地址(例如'/ abc /,/ def /')不允許跨越幾個 文件,行號相對於每個文件的開頭,$表示 到每個文件的最後一行,並且從R命令 調用的文件在每個文件的開始處倒回。

加-s也沒有-s在同一

[[email protected] ~]# cat 1 |sed -s -n '/1/p' 
12345a6789a99999a 
12345a6789a99999b 

[[email protected] ~]# cat 1 |sed  -n '/1/p' 
12345a6789a99999a 
12345a6789a99999b 

1 file is 
cat 1 
12345a6789a99999a 
12345a6789a99999b 

如何使用-s?

回答

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 
+0

很好的例子選擇和很好的解釋 –