Unix Shell - Sed pattern macth

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > June 2006 > Sed pattern macth





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Sed pattern macth
kunjathi@gmail.com

2006-06-26, 7:33 am

Hi

I've below string.

acl add name=FTP_1 audit=traffic auth_needed=no dest=ipaddr:Data1
dest_burb=external authmethods='' source=ipaddr:Data2

acl add name=FTP_2 varaiblestring=xxxxx dest=ipaddr:Dat1
dest_burb=external authmethods='' variablestring=xxxx
source=ipaddr:Data2


How can I extract "dest=ipaddr:Data1" and "source=ipaddr:Data2" from
this. The pattern before and after these string are varying. My purpose
is to extract info based on the 'dest=' and "source=" string.

Regards
AJ

Chris F.A. Johnson

2006-06-26, 1:22 pm

On 2006-06-26, kunjathi@gmail.com wrote:
> Hi
>
> I've below string.
>
> acl add name=FTP_1 audit=traffic auth_needed=no dest=ipaddr:Data1
> dest_burb=external authmethods='' source=ipaddr:Data2
>
> acl add name=FTP_2 varaiblestring=xxxxx dest=ipaddr:Dat1
> dest_burb=external authmethods='' variablestring=xxxx
> source=ipaddr:Data2
>
>
> How can I extract "dest=ipaddr:Data1" and "source=ipaddr:Data2" from
> this. The pattern before and after these string are varying. My purpose
> is to extract info based on the 'dest=' and "source=" string.


str="acl add name=FTP_2 varaiblestring=xxxxx dest=ipaddr:Dat1 dest_burb=external authmethods='' variablestring=xxxx source=ipaddr:Data2"
temp=${str%%dest=*}
temp=${str#"$temp"}
eval "${temp%% *}"

temp=${str%%source=*}
temp=${str#"$temp"}
eval "${temp%% *}"

echo "dest=$dest source=$source"

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Michael Tosch

2006-06-26, 1:22 pm

kunjathi@gmail.com wrote:
> Hi
>
> I've below string.
>
> acl add name=FTP_1 audit=traffic auth_needed=no dest=ipaddr:Data1
> dest_burb=external authmethods='' source=ipaddr:Data2
>
> acl add name=FTP_2 varaiblestring=xxxxx dest=ipaddr:Dat1
> dest_burb=external authmethods='' variablestring=xxxx
> source=ipaddr:Data2
>
>
> How can I extract "dest=ipaddr:Data1" and "source=ipaddr:Data2" from
> this. The pattern before and after these string are varying. My purpose
> is to extract info based on the 'dest=' and "source=" string.
>
> Regards
> AJ
>



awk '{for(i=1;i<=NF;++i)if($i~/^dest=|^source=/)print $i}'

--
Michael Tosch @ hp : com
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com