LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-04-2008, 09:53 PM   #1
adrian99420
LQ Newbie
 
Registered: May 2008
Posts: 1

Rep: Reputation: 0
help...how to replace string using Perl


Hi,

I wish to create a .bat file with the following content:

Code:
Set new=bye
perl -pi -i.bak -e "s/hello/new/g" hello.txt
pause
I wish to replace the string "hello" to "bye" of a file hello.txt. However, the string keep changing to "new", I already assign new=bye (line1), so how can I replace the string "hello" to "bye"?

Million thanks in advance...I need this in urgent....
 
Old 05-05-2008, 06:49 AM   #2
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 59
Drop the first line (Set new=bye), and make the second one look like this:
Code:
perl -i.bak -pe 's/hello/bye/g' hello.txt
I don't know anything about batch files or what that pause command is meant to do, for what that is worth. But the problem with the file as you wrote it seems to be that the Perl one-liner says "substitute any example of 'hello' with 'new' (including multiple times on one line)." The Perl one-liner is completely distinct from the Set command (I would think), so it can't "see" that you have assigned 'new' the value 'bye'. In any case, you shouldn't need two lines.

Last edited by Telemachos; 05-05-2008 at 06:51 AM.
 
Old 05-05-2008, 07:34 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,360

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
First post ...
... urgent ...

Homework ???.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
sed replace string octeto Programming 4 06-06-2007 02:09 AM
how to replace string by other one in a file & without perl ? Xeratul Programming 4 05-25-2007 11:13 PM
How can I replace this string with another using sed? dave4545 Programming 7 01-27-2006 10:58 AM
Perl : Troubles to replace a string. philipina Programming 4 07-26-2004 05:09 AM
problem in perl replace command with slash (/) in search/replace string ramesh_ps1 Red Hat 4 09-10-2003 01:04 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration