Tolgar
asked on
How to edit some lines of an existing file in Perl?
Hi,
This is the code I tried to use to open and edit some matching lines of an existing file. But it looks like, it does not work.
Can you please let me know what I am doing wrong?
Thanks,
This is the code I tried to use to open and edit some matching lines of an existing file. But it looks like, it does not work.
Can you please let me know what I am doing wrong?
open my $TEMPFILE, "+<$file"
or die "Couldn't open temp file: $! \n Check if the temp file is created.";
while (<$TEMPFILE>){
s{ \w+ , \s \w+ \s+ \d+ , \s 20\d\d \s+ \d\d : \d\d : \d\d }{Weekday, Month DD, 20YY HH:MM:SS}xmsg;
s{ / 20 \d\d \d\d \d\d _ \d\d \d\d }{/20YYMMDD_HHMM}xmsg;
s{href="(file://///).*?(/20YYMMDD_HHMM)}{$1***$2};
}
close $TEMPFILE;
}
Thanks,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Solution: either write each read and / or manipulated line to a temporary file, then truncare and rename the files at the end, alternatively call sed.