Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Sed and Awk (http://www.programmingforums.org/forum22.html)
-   -   Printing only from the matching exp to the end of line? (http://www.programmingforums.org/showthread.php?t=4954)

hippie Jul 18th, 2005 9:54 AM

Printing only from the matching exp to the end of line?
 
Hello there! :)

Is there a way to print only from the matching expression to the end of line ?


Example, ( exp: /DC/ )

OU=TI,OU=Clientes,OU=TI-RIO,OU=Unidades,DC=crp,DC=pes,DC=biz

Output should be:

DC=crp,DC=pes,DC=biz


Thanks!
hippie :)

jim mcnamara Jul 18th, 2005 4:57 PM

:

awk ' {if ( $0 ~ /DC/) print substr($0,index($0,"DC")) }' <filename>

sample run:
:

original file:
OU=TI,OU=Clientes,OU=TI-RIO,OU=Unidades,DC=crp,DC=pes,DC=biz
OU=TI,OU=Clientes,OU=TI-RIO,OU=Unidades
OU=Unidades,DC=crp2,DC=pes2,DC=biz2
DC=crp,DC=pes,DC=biz,OU=Unidades,DC=crp,DC=pes,DC=biz

this command
 awk ' {if ( $0 ~ /DC/) print substr($0,index($0,"DC")) }' filename

produced the following:

DC=crp,DC=pes,DC=biz
DC=crp2,DC=pes2,DC=biz2
DC=crp,DC=pes,DC=biz,OU=Unidades,DC=crp,DC=pes,DC=biz



All times are GMT -5. The time now is 1:12 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC