magento
asked on
perl one line help
Hi ,
Input file:
image1.jpg,image2.jpg
image3.jpg,image4.jpg
image5.jpg
Output file:
/image1.jpg,/image2.jpg
/image3.jpg,/image4.jpg
/image5.jpg
I have tried the below code , but / appends only to 1st image in a line.
Thanks
Input file:
image1.jpg,image2.jpg
image3.jpg,image4.jpg
image5.jpg
Output file:
/image1.jpg,/image2.jpg
/image3.jpg,/image4.jpg
/image5.jpg
I have tried the below code , but / appends only to 1st image in a line.
Thanks
perl -pe 's#^#/#;s#,#,/#g' input > output
ASKER
Hi Ozo ,
This is what i have tried , please advice.
This is what i have tried , please advice.
use strict;
use warnings;
my $file = shift or die "üsage: $0 filename";
open FH , $file or die "ünable to open file : $!";
my @data = map { chomp; $_ } <FH> ;
foreach (@data) {
my @fs = split (",",$_);
print "/",join (",",@fs) ,"\n";
}
close FH;
exit;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many thanks ozo .