LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-09-2010, 01:57 PM   #1
bigbigwhitecat
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Rep: Reputation: 0
need help in perl. new to it


Hi

I need to write a perl script which takes input as follows:-

perl abc.pl <input_file file1.log> <output_file file2.xml> <stringx1> <to be replaced by string y1> <stringx2> <to be replaced by string y2> .... <stringx.n> <to be replaced by string y.n>

logic:- file1.log contains some lines of text.
the stringx1 in file1.log gets replaced by string y1
the stringx2 in file1.log gets replaced by string y2
.
.
.
.
.
.
the stringxn in file1.log gets replaced by string yn
the new file file2.xml is created with the modifications..

Can you please help me with this?

Regards,
Anurag
 
Old 04-09-2010, 02:15 PM   #2
troop
Member
 
Registered: Feb 2010
Distribution: gentoo, arch, fedora, freebsd
Posts: 379

Rep: Reputation: 97
Code:
#!/usr/bin/perl -w
open (F1,"<".$ARGV[0]);
open (F2,">".$ARGV[1]);
my $ARGC=scalar(@ARGV);
while(<F1>)
{
    my $str = $_;
    my $i=0;
    for($i=2;$i<$ARGC;$i+=2) {
      $str =~ s/$ARGV[$i]/$ARGV[$i+1]/g;
    }
    print F2 $str;
}
close(F2);
close(F1);

Last edited by troop; 04-09-2010 at 02:18 PM.
 
1 members found this post helpful.
Old 04-09-2010, 02:24 PM   #3
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Linux 11 (Bullseye)
Posts: 3,407

Rep: Reputation: 141Reputation: 141
You're free to post what you want, of course, but he gets no benefit if you do his homework for him.
 
Old 04-09-2010, 02:47 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Quakeboy02 View Post
You're free to post what you want, of course, but he gets no benefit if you do his homework for him.
I agree totally.

'Help' usually means the person asking does SOME part of the work.
 
Old 04-09-2010, 03:42 PM   #5
bigbigwhitecat
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by TB0ne View Post
I agree totally.

'Help' usually means the person asking does SOME part of the work.
sorry people, but i do not know perl at all...sorry for asking, if it was wrong to ask.
 
Old 04-09-2010, 03:57 PM   #6
bigbigwhitecat
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Hi troop

Thanks for the help.. this is an excellent script.. works exactly as desired.. thanks once again..

u saved me man..

Regards,
Anurag
 
Old 04-09-2010, 04:29 PM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by bigbigwhitecat View Post
sorry people, but i do not know perl at all...sorry for asking, if it was wrong to ask.
Not wrong to ask for HELP at all. We're very glad to help anyone who needs it. But if you want a script, you have to demonstrate that you're actually doing some work, not expecting someone to write it for you.
 
Old 04-09-2010, 05:52 PM   #8
cola
Senior Member
 
Registered: Sep 2007
Posts: 1,045

Rep: Reputation: 65
Quote:
Originally Posted by bigbigwhitecat View Post
sorry people, but i do not know perl at all...sorry for asking, if it was wrong to ask.
Do some google about perl.
 
  


Reply

Tags
linux, perl



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to find libmail-mbox-messageparser-perl and libmailtools-perl for Fedora 11 almac58 Linux - Software 4 11-18-2009 03:17 AM
LXer: Installing Eclipse, the Epic Perl plugin and my first Perl GUI program LXer Syndicated Linux News 0 05-08-2009 06:41 PM
RHEL4u2 perl localtime() call issues (perl & glibc) Brad.Scalio@noaa.gov Linux - Enterprise 3 01-23-2007 09:27 PM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
chrooting apache v2 (php, ssl, perl support) ; perl configuration markus1982 Linux - Security 3 01-26-2003 06:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration