Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search and Replace email address within text file on command line

Status
Not open for further replies.

gareth001

Technical User
Feb 4, 2003
43
GB
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"

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
 
Code:
perl -pe "s/--d--/\"email@domain.com\"/g";
 
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[red][bold]\[/bold][/red]@domain.com/g[red][bold];[/bold][/red]" input.txt > output.txt
Also, it looks like you have the semicolon in the wrong spot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top