Sed pattern macth

Sed pattern macth

Post by kunja.. » Tue, 27 Jun 2006 19:50:50



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

 
 
 

Sed pattern macth

Post by Chris F.A. Johnso » Tue, 27 Jun 2006 22:25:05



> 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

 
 
 

Sed pattern macth

Post by Michael Tosc » Wed, 28 Jun 2006 00:40:36



> 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}'

--

 
 
 

1. sed pattern replacement question with pattern duplication

I would like to duplicate an unknown pattern (e.g. xxx) which is enclosed by an opening
and closing bracket [  ] and add some more text (e.g. bbb ccc and ddd).

Example:

blah1 blah2 blah3[xxx]blah4 blah5 blah6

should be afterwards:

blah1 blah2 blah3bbbxxxcccxxxdddblah4 blah5 blah6

The brackets could occur multiple time in a row.
Other Example (this time the unknown patterns enclosed by the brackets are yyy and zzz:

foo1 foo2 [yyy]foo3 foo4[zzz]   foo5

Should be transferred to:

foo1 foo2 bbbyyycccyyydddfoo3 foo4bbbzzzccczzzddd    foo5

How do I specify this rule for an sed command ?

Matt

2. smbfs experience

3. Substitute this pattern for that pattern EXCEPT if this is true with sed???

4. Obtaining Ethernet address under Solaris

5. Searching N'th line of a pattern with SED

6. wxWindows?

7. How to print a word following a pattern in sed, awk or perl

8. Partiton table info is resident in memory?

9. sed pattern matching

10. Use shell variable as sed pattern?

11. Sed: merging lines recursively depending on line pattern

12. Tricky SED matching and replace pattern for reformatting source codes brackets

13. SED, EX, pattern maching PUZZLEs ...