星期二, 元月 05, 2010

使用 SED 移除空白行(列)

使用 sed 來移除整列都是空白(沒有資料)的行, 語法如下:

sed '/^$/d'

註: sed '/\n/d' 沒有用. XD

SED 移除整列 範例

常使用在移除註解時, ex: (移除開頭是 # 的列)

cat xxx.conf | grep -v '^#' | sed '/^\s*$/d'

相關網頁

相關標籤

this is comment icon [回覆]

cat xxx.txt | perl -e 'while( ) { chomp(); if ( $_ !~ /^$/ ) { print qq|$_\n|; } }'
cat xxx.txt | perl -e 'while( ) { chomp(); if ( $_ !~ /^#/ ) { print qq|$_\n|; } }'

用perl 寫的
好像有點長 XD

Comment by johnpupu (01/06/2010 00:13)

this is comment icon 回 johnpupu [回覆]

cat xxx.conf | perl -e 'while(<>) { chomp(); if ( $_ !~ /^\s*#/ ) { if ($_ !~ /^$/) { print qq|$_\n|; } } }'
哈, 確實是很長~ :D

Comment by Tsung (01/06/2010 09:34)

this is comment icon [回覆]

http://www.linuxask.com/questions/remove-empty-lines-in-a-file 實在太多方法了
Comment by DavidSon (01/07/2010 21:46)

this is comment icon 回 DavidSon [回覆]

jon

感恩, 真是太強了.. Orz..

Comment by Tsung (01/08/2010 11:33)
Add this page to del.icio.us

發表迴響

標題

內容 (限制 1000 字)

暱稱

電子郵件

個人網頁


 authimage


PS: 若無法留言, 請先確認是否有打開 JavaScript, 造成您的困擾, 實在萬分對不起 Orz...(如果無法留言, 勞煩可以發信給我好嗎? 謝謝.)
PS2: 若您的留言被誤判, 我都會再自行看過, 不需要一直重覆張貼~