使用awk/sed删除双新行

tsu*_*nka 3 unix sed file

嘿大家.我有一个充满数据的文件,每行包含类似"755545; 45634; 1244"的内容.有时在某处可能会出现未知数量的额外新行,这是我不想要的.例:

256163;16816;1651
16156;165165;1165

15153;135135;15351
15153;1351;8



165;15313;153513
254;45;45
Run Code Online (Sandbox Code Playgroud)

期望的输出:

256163;16816;1651
16156;165165;1165    
15153;135135;15351
15153;1351;8
165;15313;153513
254;45;45
Run Code Online (Sandbox Code Playgroud)

使用unix中的awk/sed实用程序可以轻松完成吗?

Fre*_*ihl 9

如果"空"行上没有空格,@ Luixv的答案是正确的.如果存在空格,请改用:

sed '/^[ \t]*$/d'
Run Code Online (Sandbox Code Playgroud)

那是括号内\ t之前的空格,即[space\t]

如果这不起作用,您可能会遇到换行问题.做一个:

$ file test_file
test_file: ISO-8859 text, with CRLF, LF line terminators
Run Code Online (Sandbox Code Playgroud)

如果您获得上面的输出,请使用以下命令将文件转换为unix:

$ dos2unix test_file
Run Code Online (Sandbox Code Playgroud)


Lui*_*ixv 6

sed'/ ^ $/d'