Perl one liner is not working inside perl script -
i'm trying remove string @my.mail.com file - list.txt, using 1 liner perl script. (perl script kicked off windows server)
r12355 test@my.mail.com r29555 test@my.mail.com r29555 trial@my.mail.com @my.mail.com r295721 xxx@my.mail.com r295722 yyyy@my.mail.com @my.mail.com r295140 test@my.mail.com r295145 test@my.mail.com @my.mail.com
below options have tried while calling inside perl script:
`perl -pi.bak -e 's/\s+\@my\.mail\.com\s+//g;' d:\\myfolder\\list.txt`; system("perl -pi.bak -e 's/\s+\@my\.mail\.com\s+//g;' d:\\myfolder\\list.txt"); system( q( perl -l -pi.bak -e 's/\s+\@my\.mail\.com\s+//g;' d:\\myfolder\\list.txt ) );
i'm expecting result
r12355 test@my.mail.com r29555 test@my.mail.com r29555 trial@my.mail.com r295721 xxx@my.mail.com r295722 yyyy@my.mail.com r295140 test@my.mail.com r295145 test@my.mail.com
not sure if i'm missing silly , inputs appreciated. in advance!
there 2 problems here. firstly have escaped backslashes in file path not in regex pattern, , secondly have used single quotes around parameter -e
option, windows doesn't recognise delimiters
this variation should work you. uses single quotes (actually q{...}
) protect backslashes nothing needs escaped
system q{perl -pi.bak -e "s/\s+\@my\.mail\.com\s+//g" d:\myfolder\list.txt};
however poor practice shell out perl process within perl program. can done directly in main code adding this, more readable , less easy wrong
{ local @argv = 'd:\myfolder\list.txt'; local $^i = '.bak'; while ( <> ) { s/\s+\@my\.mail\.com\s+//g; print; } }
Comments
Post a Comment