Solved

perl one line help

Posted on 2014-01-04
4
251 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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 …
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…

749 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