[英]remove blank line at the end of a text file converted from an excel file
[英]Remove everything starting from the first blank line in a text file
我有一個文本文件,我想從中刪除所有從第一個空白行開始的行,最好使用一些標准的Unix工具,如sed / awk。
使用Perl
perl -pe '/^\s+$/ and exit' < in.txt > out.txt
-p
在命令行中使用-e
加上while(<>) {
並print }
。
這應該工作:
awk '/^$/ {exit}{print}' < data
輸入樣例:
one two thre four five six seven eight nine ten eleven twelve thirteen fourteen fifteen THE END
樣本輸出:
# awk '/^$/ {exit}{print}' < data one two thre four five six seven
順便說一句,如果您的“空白行”可能包含空格和/或制表符,請使用:
'/^[ \t]*$/ {exit}{print}'
與sed:
$ sed -i '/^\s*$/,$d' file
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.