Hacker News new | ask | show | jobs
by MrQuincle 3436 days ago
That was a tough one. In the end something like this:

< war_and_peace.txt tr -s '!' | sed 's/!\([a-z]\)/\1/g' | sed 's/!\( [a-z]\)/\1/g' | sed 's/!\.!/./g' | sed 's/ !/ /g'

However, I don't think I learnt much from that. :-)

1 comments

Mine was a bit more procedural, if that's what you were looking for:

  awk '{l++;gsub("!","");t[1]=4;t[4]=2;t[9]=3;o=$1;for(i=2;i<=NF;i++){o=o " " $i (i==t[l]?"!":"")};print o}' war_and_peace.txt