Solved

perl one line help

Posted on 2014-01-04
4
252 Views
Last Modified: 2014-01-05
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
0
Comment
Question by:magento
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 39756323
perl -pe 's#^#/#;s#,#,/#g' input > output
0
 
LVL 5

Author Comment

by:magento
ID: 39756335
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

0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 39756353
use strict;
use warnings;
@ARGV or die "Usage: $0 filename\n";
while( <> ){
    s#^#/#;
    s#,#,/#g;
    print;
}
0
 
LVL 5

Author Closing Comment

by:magento
ID: 39758155
Many thanks ozo .
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question