Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

perl one line help

Posted on 2014-01-04
4
Medium Priority
?
256 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Six Sigma Control Plans

636 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