awk できちんとマッチしない
awk '/^----/,/^____/{next}{print}'
というものが正常に動作していないというものです。具体的には、以下のようなファイルを使っています。
From - Sun Sep 18 12:55:25 2005 (...) Some text I want to keep Some text I want to keep ------------------------------------------------------- SF.Net email is sponsored by: Tame your development..... ________________________________________ this text should stay email@address https://address/should/stay From - Sun Sep 18 12:58:18 2005 (...) 2 Some text I want to keep 2 2 Some text I want to keep 2 A cool diagram which needs to stay:
回答は以下のようなものです。
$ awk '/^-+$/,/^_+$/{next}{print}'
$ awk '/^-+$/,/^_*$/{next}{print}'
{a[NR]=$0} /^-+$/{from=NR} /^_+$/{to=NR} END{ if(from < to) { for(i=1;i<from;i++) print a[i] for(i=to+1;i<NR;i++) print a[i] } }
awk 1 RS="-+\n[^-]**_+\n" filename
awk 1 RS="-+[^-]*_+" filename
しかし、awker という種族は Golf が好きですね。