CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Delete lines that not matches a pattern

 



edelcastillo
New User

Aug 22, 2006, 3:28 PM

Post #1 of 2 (2413 views)
Delete lines that not matches a pattern Can't Post

Friends:

I can't figure out how to do this... I have a variable "$var_search" with a text like this...

##eropiu opiuwqer oiwqureiou qopiuwer
##iuyasdf iouyasdf iuysadf
@@aoiuasdf oiausdf oiusadf
##asdf oiuqwer lkj˝lk a˝lkj
@@adsf˝jh kljhkljh iyqwer
&&asdfasd asdfasdf sadfadfa
%%asdfasdf asdfasdfa asdadsf
@@wqeoiruy yqwer qoyqwer
##sadff asdfads asdfasdf

I want to delete all lines that not have a @@ on it to finaly have:

@@aoiuasdf oiausdf oiusadf
@@adsf˝jh kljhkljh iyqwer
@@wqeoiruy yqwer qoyqwer

I can not figure out how to do it using s///g or tr///d. Thanks in advance for your help.

Erick.


davorg
Thaumaturge / Moderator

Aug 24, 2006, 6:28 AM

Post #2 of 2 (2398 views)
Re: [edelcastillo] Delete lines that not matches a pattern [In reply to] Can't Post

Something like this perhaps...


Code
$_ = <<'END'; 
##eropiu opiuwqer oiwqureiou qopiuwer
##iuyasdf iouyasdf iuysadf
@@aoiuasdf oiausdf oiusadf
##asdf oiuqwer lkj˝lk a˝lkj
@@adsf˝jh kljhkljh iyqwer
&&asdfasd asdfasdf sadfadfa
%%asdfasdf asdfasdfa asdadsf
@@wqeoiruy yqwer qoyqwer
##sadff asdfads asdfasdf
END

my $data = join "\n", /(\@\@.+)/g;

print $data;


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives