Grep:pipe delimited output

Hi,

I am trying to search for a string in a file and print all the matched lines as pipe delimited format.

My command is

cat m_gid_trans.XML|grep -i '<TABLEATTRIBUTE NAME ="Lookup cache directory name"'

The output I am getting is

 <TABLEATTRIBUTE NAME ="Lookup cache directory name" VALUE ="PMCacheDir"/>
        <TABLEATTRIBUTE NAME ="Lookup cache directory name" VALUE ="$PMCacheDir"/>
            <TABLEATTRIBUTE NAME ="Lookup cache directory name" VALUE ="$PMCacheDir"/>
            <TABLEATTRIBUTE NAME ="Lookup cache directory name" VALUE ="/gid/Cache"/>
            <TABLEATTRIBUTE NAME ="Lookup cache directory name" VALUE ="$PMCacheDir"/>
            <TABLEATTRIBUTE NAME ="Lookup cache directory name" VALUE ="$PMCacheDir"/>

My desired output is something like

<TABLEATTRIBUTE NAME ="Lookup cache directory name" VALUE ="$PMCacheDir"/>|<TABLEATTRIBUTE NAME ="Lookup cache directory name" VALUE ="$PMCacheDir"/>

I tried to put

sed -e :a -e 'N;s/\n/|/; ta'

at the end of the command and run, but it did not show any result.

Please help,
Thanks

Try in Awk

 
 awk 'BEGIN{ORS="|"}/TABLEATTRIBUTE NAME ="Lookup cache directory name"/' input_file

You can make use

grep -i '<TABLEATTRIBUTE NAME ="Lookup cache directory name"' input_file |  tr "\n" "|"

for desire o/p

It says

---------- Post updated at 07:39 AM ---------- Previous update was at 06:49 AM ----------

tr "\n" "|" is printing only the firstsearch

paste -sd\| -

Regards,
Alister

is there a way, that we can achieve this with sed?...I am sorry, am weak in UNIX