Good evening,
I have a file and wish to replace the 8th and 9th characters on the first line only no matter what they are with 44 and the file permanantly changed.
e.g. file example.txt before change:
123456789123456
hi how are you
blah
blah
file example.txt after change:
123456744123456
hi how are you
blah
blah
All answers much appreciated.
Try:
perl -i -pe 's/(.{7})../${1}44/ if $.==1' example.txt
Works perfectly.
Many thanks.
---------- Post updated 11-03-11 at 04:11 AM ---------- Previous update was 11-02-11 at 06:36 PM ----------
Morning,
I have now been asked for it in a bash script.
No perl.
Any ideas
Thanks in advance.
$ sed '1 s/\(.......\)..\(.*\)/\144\2/' test
123456744123456
hi how are you
blah
blah
---------- Post updated at 03:10 PM ---------- Previous update was at 03:09 PM ----------
$ sed '1 s/\(.\{7\}\)../\144/' test
123456744123456
hi how are you
blah
blah
binlib
5
If your file is big, the following will take no time:
echo 44 |dd of=test bs=1 seek=7 count=2 conv=notrunc