Steve Hemond wrote: > Hi ppl, > > I need to insert the ESC character followed by a couple of other > characters at the beginning of a text file without overwriting it. What > is the best way to do it?
most os would not allow you to add a few bytes at the beginning of the file without overwriting it. what you need to do is create a temp file, add the ESC character, add the 2 other characters and then copy the old file over. finally, rename the temp file back to the old file. the following does that: [panda]# od -c tmp.txt 0000000 a b c d \n 0000005 [panda]# perl -i -pe 'printf "%c**", 27 if $. == 1' tmp.txt [panda]# od -c tmp.txt 0000000 033 * * a b c d \n 0000010 here i am adding a ESC followed by '*' and '*' to tmp.txt. od is used to verify the file before and after the addition david -- s$s*$+/<tgmecJ"ntgR"tgjvqpC"vuwL$;$;=qq$ \x24\x5f\x3d\x72\x65\x76\x65\x72\x73\x65 \x24\x5f\x3b\x73\x2f\x2e\x2f\x63\x68\x72 \x28\x6f\x72\x64\x28\x24\x26\x29\x2d\x32 \x29\x2f\x67\x65\x3b\x70\x72\x69\x6e\x74 \x22\x24\x5f\x5c\x6e\x22\x3b\x3b$;eval$; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>