[thelist] Basic GREP help

Hassan Schroeder hassan at webtuitive.com
Fri Jan 14 09:17:23 CST 2005


Steve Bissonnette wrote:

> I have a list of items ... Each on it¹s own line....
> 
> 7322 - Adjustment & collection services
> 
> I need to transform that list into this ..
> 
> 7322 (a) 7322 (b) 7322 - Adjustment & collection services

> (take the 4 digit code and ³pasting it twice at the start of the line with
> the delineator between)

> What would be a GREP search pattern that would do this ?

AFAIK, grep *finds* patterns but doesn't change them; if you're
just looking for a *regular expression* that'll create the desired
output, here's one in Perl:

perl -e  'while(<>){ s/(\d{4})/$1 (a) $1 (b) $1/g;print;}' < t.txt

(where t.txt contains your list of items)

HTH!
-- 
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com

                           dream.  code.




More information about the thelist mailing list