in reply to Re: replace fist and last occurrences of N
in thread replace fist and last occurrences of N

Hey, thanks for quick reply! where do I put this line? I mean how do I use it? Thanks
  • Comment on Re^2: replace fist and last occurrences of N

Replies are listed 'Best First'.
Re^3: replace fist and last occurrences of N
by massa (Hermit) on Jul 12, 2008 at 15:27 UTC
    shell$ perl -pi.bak -le 's/(?<=[^n])n|n(?=[^n])/^/ig' yourfile.txt
    will do the substitution and leave a backup file named yourfile.txt.bak

    UPDATE: it will not work, because your file has newlines (somehow I missed it). Try this instead:

    perl -pi.bak -0377 -e 's/n([n\n]*)n/^$1^/ig' yourfile.txt
    []s, HTH, Massa