Hi all,
I want to search for a line in a file using perl script and add a line above that line.Can any one suggest me command or code to that using script.
Thanks BHarath
Hi all,
I want to search for a line in a file using perl script and add a line above that line.Can any one suggest me command or code to that using script.
Thanks BHarath
You are excepting this one
perl -p -i -e 's/raj/rani/g' test2.txt
perl -lane 'if (/pattern/) {print "newword\npattern"}else{print $_}' filename.txt
Or:
# cat infile
asa
sasaa
asasa
oooo
eee
eee
#perl -pi -e 'print "new line\n" if (/^ooo/);' infile
#cat infile
asa
sasaa
asasa
new line
oooo
eee
eee
Hi
Actually my intention is to search a line which have one keyword for ex:-SLAVE,after searching i want add one line above this line.
Ex:- SLAVE"";---statement
now in this file i want to search for this word slave and above this line i want to add new line
//nes line added
SLAVE"";---statement
I want a perl script to do all this.
ok.. and what's the problem with the suggestions above ?
#perl -pi -e 'print "new line\n" if (/SLAVE/);' infile