I can edit multiple files in place using the -p -i -e command line options:
ruby -pi -e 'sub(/a/,"b")' file*
How can I edit only the first line of each file? This works for one file only:
ruby -pi -e 'sub(/^/,"New line goes at top\n") if $. == 1' file1
This does not work:
ruby -pi -e 'sub(/^/,"New line goes at top\n") if $. == 1' file*
The line-number variable,
$., is not reset for each file.
My solution is to check for
$FILENAME changing and then keeping track of what
$. was at that point. Is that it, or is there a more elegant solution?