in reply to Re^3: command line replace incorrectly indexes $.
in thread command line replace incorrectly indexes $.

I'm sorry. I thought I was still logged in before. There was a typo in my last response: The result I want is:

a.htmlb.html
Before
orgtext orgtext 
orgtext
orgtext
orgtext
orgtext orgtext
orgtext
orgtext
orgtext
After
1 1
2
3
4
1 1
2
3
4

  • Comment on Re^4: command line replace incorrectly indexes $.

Replies are listed 'Best First'.
Re^5: command line replace incorrectly indexes $.
by ikegami (Patriarch) on Oct 18, 2007 at 01:01 UTC

    There's so many inconsistencies in your posts! You showed newlines occasionally being added, the counter magically reseting for the second file, and different behaviours for the same code. The latest is a requirement you didn't even mention initially. If anything, you asked for the opposite.

    The following code replaces the string with the line number. The close resets the counter for every file on the command line.

    perl -pi -e 's/orgtext/$./eg; close(ARGV) if eof(ARGV)' *.html