Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Regular Expression Search and parse?



 Yea, I ended up doing something like that, but I was hoping for a more 
general purpose utility as I may want to do a bunch of these. 

Alas, I may have to write one. 

Eugene Gorelik wrote: 
> This is easily doable with perl : 
> 
>    open(MYFILE,'/path/to/file'); 
>     while (<MYFILE>) { 
>         chomp; 
>            if ( $_ =~ /^(.*)\[ISBN:(.*)\](.*)$/){ 
>                    print "ISBN $2"; 
>              } 
>     } 
> 
> Second (.*) is your ISBN number 
> 
> ------------This code hasn't been tested-------------- 
> 
> - Eugene 
> 
> On Jan 17, 2008 4:13 PM, Mark Woodward < [hidden email] 
> <mailto:[hidden email]>> wrote: 
> 
>     We all know what "grep" does, but does anyone know of a utility that 
>     uses parameterized regular expressions as a search mechanism and 
>     outputs 
>     only the parameters that were found? Sort of like the regex 
>     function call. 
> 
>     So, if I have file with a lot of lines that look like this: 
> 
>     Title: The Long and Winding Road [ISBN:123456] 
>     Descr: A boring book about boring roads 
>     Author: A dull cab driver 
>     ... 
> 
>     I could execute: 
> 
>     myregex "Title:*\[ISBN:$1\]" file.txt 
>     123456 
>     ... 
> 
>     and get an output of all the ISBN numbers 
> 
> 
>     -- 
>     This message has been scanned for viruses and 
>     dangerous content by MailScanner, and is 
>     believed to be clean. 
> 
>     _______________________________________________ 
>     Discuss mailing list 
>     [hidden email] <mailto:[hidden email]> 
>     http://lists.blu.org/mailman/listinfo/discuss
> 
> 


BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org