NDxiak
July 22, 2009, 12:27pm
1
Hey,
I have 10 lines of text ... And I would like to Insert prefix for each line with static text.
perl -pi -e 's/()/$1 TEST$./' data.txt
Each line will have different static prefix, Code above works perfectly for 1st line ... I'm just not sure how I can run same command for 2nd line 3rd etc ....
Thank You in Advance
it should make the change for all the lines in the file. But why is there nothing in between the parenthesis? /()/
NDxiak
July 22, 2009, 12:44pm
3
Hey I guess I need to put (\t\t) for Tabs ?
And again how I can specify that Line2 will have Prefix ABCD Line3 EFG etc ?
perl -pi -e 's/\t/$1 TEST $./' data.txt
Because right now It only adds prefix for 1st line ...
Thank You
this won't do anything
perl -pi -e 's/\t/$1 TEST $./' data.txt
$1 is never defined because there are no capturing parentheses in the search side of the regexp. Maybe this is what you mean:
perl -pi -e 's/(\t)/$1 TEST $./' data.txt
why it does not affect the entire file and only the first line, I don't know.
NDxiak
July 22, 2009, 5:32pm
5
This code works almost as I would like it .. the only problem is that is not adding text in front of existing line ...
perl -i -ple 'print q{Text to Insert} if $. == 9; close ARGV if eof' data.txt