hi all... i got some requirment where i need to insert some values into first record of flat file. i am using perl for that job.
var1=456
var2=789
echo `perl -p -i -e "s/U/\${var1}U${var2}/g;" myFile.txt`
but it is writing into all records which has U.... can anyone help me out in this...
echo `perl -p -i -e "1,s/U/\${var1}U${var2}/g;" myFile.txt` try this not sure..
its actually doing the same job... it is inserting into all line...
i want to insert into first record only... any other correct option..
try sed, may work
sed '1s/old/new/' filename
actually i want to edit into a file which sed wont do... can u help in perl plz
try it..
echo `perl -p -i -e "1s/U/\${var1}U${var2}/g;" myFile.txt`
and if your man page shows sed -i option then sed can edit file otherwise you can't do it by perl also..
i dont have -i for sed in my tool.
If your file is small you can slup it:
perl -e '@=<>; print "test\n",@' x
# Where test here is what you want added
But its sort of clunky and not as efficient as maybe:
perl -pe '$i++||print "test\n"' file > newfile
# Where test is what you want added