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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Substitution in PERL like SED does...Help!!!!!

Status
Not open for further replies.

suhaimi

Technical User
Aug 3, 2001
71
US
Hi all,
How do I do this in perl command line???
I have SED script:
myvar="test"
cat a.txt|sed '/'$myvar'/ !s/.*MYSTR/#&/g'
What does it do is it will PUT '#' character in front of a whole line of strings that --> CONTAIN &quot;MYSTR&quot; <-- BUT
--> DO NOT CONTAIN &quot;test&quot; <--.

Please help, how do I do this in perl command line???

Thanks,
Suhaimi


 
while(<>){
if(/MYSTR/){
unless(/test/){
print '#';
}
print;
}
}

That will do it, though not on the command line. Hop on over to the Perl forum forum219 if you really do need a command line solution. Mike
________________________________________________________________________________

&quot;Experience is the comb that Nature gives us, after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top