Can someone suggest an elegant way to accomplish this?
Input:
test instant ()
test instant ()
...
test instant () //total 1000 lines
output should be:
test instant1 ()
test instant2 ()
test instant1000()
The empty lines are in my input files and there are many files under the same directory that I need to process at once.
I tried this to replace many files in the same dir and didn't work.
for file in ./*; do perl -i -000pe 's/instance$& . ++$n/ge' "$file"; done
errors:
Substitution replacement not terminated at -e line 1.
Substitution replacement not terminated at -e line 1.
and I also tried this:
perl -i -pe 's/instant/$& . ++$n/ge' *.vs
It worked but the index just kept incrementing from one to another file. I'd like to reset that to 1 upon change to a new file. Any good suggestions?
find . -type f -exec perl -pi -e 's/instant/$& . ++$n{$ARGV}/ge' {} +
works but it replaced all other files shouldn't be replaced. I prefer to just replace the files with *.txt
only.
test instant ()
? – terdon Feb 26 '14 at 19:54