
Laurent_R
Veteran
/ Moderator
Aug 27, 2012, 11:46 AM
Post #6 of 18
(6248 views)
|
Re: [gerble1000] how to rewrite a specific line of a txt file
[In reply to]
|
Can't Post
|
|
Hi, something like this (quick untested example):
use strict; use warnings; my $infile = "in_file.txt"; my $outfile = "out_file.txt"; open my $in, "<", $infile or "die cannot open $infile $! \n"; open my $out, ">", $outfile or "die cannot open $outfile $! \n"; while (my $line = <$in>){ chomp $line, # change line if needed. I'll assume for the example you want to replace multiple spaces where they occur by one single space $line =~ s/\s+/ /g; print $out $line, "\n"; } close $in; close $out;
Then, of course, you may want to delete the in_file et rename the out-file into the in_file.
(This post was edited by Laurent_R on Aug 27, 2012, 11:48 AM)
|