Solved

perl one line help

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
perl script to count sepecial characters in a file 7 131
Perl 101 11 68
Perl efficient DB Call 8 75
Perl tar error 8 29
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now