![](/img/trans.png)
[英]Is there a way to remove everything before and including a tab (or space) for each line of a file using sed?
[英]Remove everything before a blank line using sed
可以說我有一個像這樣的文件:
"Testing is important"
Nothing is impossible
輸出應為:
Nothing is impossible
這意味着sed刪除了新行之前的所有內容。 另外,我需要確保它可以在Windows的bash上運行。
請幫忙。
你可以試試這個
sed '1,/^\s*$/d' file
\\ s是空格,與
sed '1,/^[[:blank:]]*$/d' file
Sed支持將行尋址為數字和匹配的正則表達式。 您可以刪除從1開始並以空行結尾的所有行:
sed -e '1,/^$/d'
在Windows上,您的文件可能包含回車符,在這種情況下,您可以使用:
sed -e '1,/^\r*$/d'
(假設GNU sed)
要允許一個以上的空行和最后一個空行之后的多行,可以使用如下所示的內容:
awk 'BEGIN{RS=ORS=""}{a=$0}END{print a}' file
這將取消Record Separator RS
,因此每個塊/段落都被視為單獨的記錄。 它給每個記錄的變量a
,然后打印的最后一個值a
一旦該文件已被處理。 輸出記錄分隔符ORS
也未設置,因此沒有換行符附加到最后一個塊。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.