×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Search and Replace email address within text file on command line

Search and Replace email address within text file on command line

Search and Replace email address within text file on command line

(OP)
I've a windows batch command that is being generated by an external product which inserts variables which will replace sections within a space delimeted data file. So below I'm searching for the value of "--d--" and replacing it with "email@domain.com"

CODE --> Perl

perl -pe "s/--d--/email@domain.com                 /g"; C:\input.txt > C:\output.txt 

The problem I have is because perl treats "@" as a system command and ignores everything after "email". The typical solution of adding a \ before the @ sign won't work, as the external product can't accomodate this. Is there a way I can treat everything that comes across within the email variables as non system variables?

I'm wanting to do this as a single line command.

Thanks

A quote is the epiphany of intelligence

RE: Search and Replace email address within text file on command line

CODE

perl -pe "s/--d--/\"email@domain.com\"/g"; 

RE: Search and Replace email address within text file on command line

Quote:

perl treats "@" as a system command and ignores everything after "email"
that's not exactly right - it's treating that particular bit of your code as the @domain array, which is empty. The easiest way to get around that is to escape the @ symbol by doing something like:

CODE

perl -pe "s/--d--/email\@domain.com/g;" input.txt > output.txt 
Also, it looks like you have the semicolon in the wrong spot.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close