作者pat12345 (咖啡杯)
看板Perl
標題[問題] 移除#開頭的行
時間Thu Jan 8 15:26:11 2015
哈囉,大家好,
最近剛接觸perl,
想請問如何移除file.txt 裡面以#開頭的行呢?
謝謝
open FILE, "</pwd/file.txt";
open FILE1, ">new1.pl";
while (<FILE>){
if (/#/){
print FILE1 "$_\t";
}
}
close FILE
--
Sent from my Android
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.136.219.56
※ 文章網址: http://webptt.com/m.aspx?n=bbs/Perl/M.1420701974.A.243.html
※ 編輯: pat12345 (223.136.219.56), 01/08/2015 15:26:50
1F:推 DonDonMo: 可以插一行$_=~s/^#//;試試 01/08 18:39
2F:→ CindyLinz: 等等.. 他應該是想要讓整行不見吧 ^^| 01/08 18:56
3F:→ CindyLinz: 原 po 把 /#/ 改成 !/^#/ 吧 01/08 18:56
4F:→ pat12345: ok囉,真是感謝啊^^| 01/08 23:34
5F:推 herculus6502: perl -pe "s/^#.*//" file.txt > new1.pl 01/09 10:26
6F:→ xatier: grep -v ^# file 這不用用 Perl 吧 XD 01/09 13:44