Link to home
Start Free TrialLog in
Avatar of magento
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
Avatar of ozo
ozo
Flag of United States of America image

perl -pe 's#^#/#;s#,#,/#g' input > output
Avatar of magento
magento

ASKER

Hi Ozo ,

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;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of magento

ASKER

Many thanks ozo .