Gossamer Forum
Home : General : Perl Programming :

Replacing Initial Character Only in a File

Quote Reply
Replacing Initial Character Only in a File
How to remove the first few characters in a File?


I have some "\377\376" added to the beginning of the Unicode File. how to remove these Initial characters ONLY from the file?
Quote Reply
Re: [chev] Replacing Initial Character Only in a File In reply to
take the first line $first_line
and..

$first_line = s/^\w{$NUM_CHARS}/$REPLACE/i;

where:
$NUM_CHARS is how many characters you want to get rid of (or replace)
and $REPLACE is what'll be exchanged for the characters (leave blank if you want to erase them completely)

also..may need to play around with the "\w" a bit, and make a new character class for yourself, i.e. instead of \w use something like [A-Za-z0-9]

Smile