Find the answer to your Linux question:
Results 1 to 2 of 2
Hi. I am very new to Perl scripting. All I am trying to do is use a single Perl command line (in a DOS shell, sorry) that will do a ...
  1. #1
    Just Joined!
    Join Date
    Sep 2007
    Posts
    2

    Question Simple Perl Scripting Question.Need Help!!!

    Hi. I am very new to Perl scripting. All I am trying to do is use a single Perl command line (in a DOS shell, sorry) that will do a find and replace. That part I have working, but the text I am trying to replace doesn't work properly.
    Details:
    Example: I have a text file with two entries I am replacing: "eMail2" with "eMail". This works fine.
    Also, I am trying to replace "test@test.com" with "new@new.com". This is the part that will not replace correctly.
    Here is the command line I am using:

    Code:
    $perl -pi.bak -e "s/eMail2/eMail/g;s/test@test.com/new@new.com/g" "C:\test.txt"
    I know it has to do with the"@" symbol. I do not understand how to use regular expressions, thinking that may be the fix. PLEASE HELP! I know there is a way around this I just don't have the command right. Also, using sed or grep is not an option because they will not exist on the system I will run this code on.
    Thanks.

  2. #2
    Just Joined!
    Join Date
    Sep 2007
    Posts
    2

    Question ...more details

    Here is another command I tried:

    Code:
    $perl -p -i.log -e "s|(<eMail2>)(.+)(</email2>)|$1new@new.com$3|" "C:\test.xml"

    before: <eMail2>test@test.com</eMail2>

    Here is the output after the code:
    <eMail2>new.com</eMail2>

    How do I handle the "@"???

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...