Print mutliple patterns in a line using sed

Hi,

I am trying to print multiple patterns in a line using sed. But it is printing only the last occurance of a pattern.

If the line is

the the output should be
Lookup Procedure|Stored proc

But the output I am getting is

Stored proc

The code I am using is

echo '<TRANSFORMATION TYPE ="Lookup Procedure" TYPE ="Stored proc">' | sed 's/.*TYPE ="\([^"]*\)"/\1/'

Plz help.

Thanks

If perl is an option, try this:

echo  '<TRANSFORMATION TYPE ="Lookup Procedure" TYPE ="Stored proc">' | perl -ne '@s = $_ =~ /TYPE ="([^"]*)/g; print join ("|", @s)'

Another pearl:

perl -ne 'while (/(TYPE =".*?")/g){print "$1|"}'

A grep:

grep -o "TYPE =\"[^\"]*\"" | paste -d'|' -s
echo '<TRANSFORMATION TYPE ="Lookup Procedure" TYPE ="Stored proc">' | sed 's/.*TYPE ="\([^"]*\)"/\1/'

You need to have a regular expression that saves the value after both "TYPE=" in your line. You only save one.

echo '<TRANSFORMATION TYPE ="Lookup Procedure" TYPE ="Stored proc">' |sed 's/^.* TYPE ="\([^"]*\)" TYPE ="\([^"]*\)">$/\1\|\2/'

Thanks for the help, but I dont have much idea about perl.
I am finding it difficult when the line is as shown below:

<TRANSFORMFIELD LKP.LKP_GID_ERROR_LOOKUPS('P3_TRN_AMT_ZERO'),2, '| '||:LKP.LKP_GID_ERROR_LOOKUPS('P3_INVALID_TRAN_TYP'),
NULL)"/>

I get the output as

P3_TRN_AMT_ZERO'),2, '| '||:LKP.LKP_GID_ERROR_LOOKUPS('P3_INVALID_TRAN_TYP')

The command I used is :

perl -ne '@s = $_ =~ /[(]'([^"]*'[)])/g; print join ("|", @s)'

The idea is to print the word between a search string

Thanks

Can't we do it using sed or awk?

try this:

perl -ne '@s = $_ =~ /\('(.*?)'\)/g; print join ("|", @s)'

Subbeh,

I think u r a gem in Perl and unix, the result was as expected.
If u dont mind, can you please explain the code.

And plz let me know if it is possible to do using sed

Thanks

Basically you set an array ( @s = ) with all the matches it finds from the input ( $_ =~ /\('(.*?)'\)/g ) and then print the array delimited by a pipe character ( print join ("|", @s)' )

The regex matches everything between \(' and the nearest '\) .

I don't know a similar way to do this with sed. Maybe someone else knows...

Look back to my post. I created the output as you requested in your first post using only sed. Did you need something different?