Grep:pipe delimited output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep:pipe delimited output
# 1  
Old 05-14-2013
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

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

The output I am getting is

Code:
 <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
Code:
<TABLEATTRIBUTE NAME ="Lookup cache directory name" VALUE ="$PMCacheDir"/>|<TABLEATTRIBUTE NAME ="Lookup cache directory name" VALUE ="$PMCacheDir"/>

I tried to put
Code:
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
# 2  
Old 05-14-2013
Try in Awk
Code:
 
 awk 'BEGIN{ORS="|"}/TABLEATTRIBUTE NAME ="Lookup cache directory name"/' input_file

You can make use
Code:
grep -i '<TABLEATTRIBUTE NAME ="Lookup cache directory name"' input_file |  tr "\n" "|"

for desire o/p

Last edited by posix; 05-14-2013 at 09:48 AM..
# 3  
Old 05-14-2013
It says
Quote:
<TABLEAT...' too long
---------- Post updated at 07:39 AM ---------- Previous update was at 06:49 AM ----------

tr "\n" "|" is printing only the firstsearch
# 4  
Old 05-14-2013
Code:
paste -sd\| -

Regards,
Alister
# 5  
Old 05-14-2013
is there a way, that we can achieve this with sed?...I am sorry, am weak in UNIX
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get the output of w command in pipe delimited format

Since output of w command have variable number of columns I want to get the output in pipe delimited format. I tried export OFS="|"; w but that does not work. Any ideas? (4 Replies)
Discussion started by: Soham
4 Replies

2. UNIX for Dummies Questions & Answers

Need to convert a pipe delimited text file to tab delimited

Hi, I have a rquirement in unix as below . I have a text file with me seperated by | symbol and i need to generate a excel file through unix commands/script so that each value will go to each column. ex: Input Text file: 1|A|apple 2|B|bottle excel file to be generated as output as... (9 Replies)
Discussion started by: raja kakitapall
9 Replies

3. Shell Programming and Scripting

How to ignore Pipe in Pipe delimited file?

Hi guys, I need to know how i can ignore Pipe '|' if Pipe is coming as a column in Pipe delimited file for eg: file 1: xx|yy|"xyz|zzz"|zzz|12... using below awk command awk 'BEGIN {FS=OFS="|" } print $3 i would get xyz But i want as : xyz|zzz to consider as whole column... (13 Replies)
Discussion started by: rohit_shinez
13 Replies

4. Shell Programming and Scripting

Pipe delimited output

Hi All, i have the following command df|awk '{print $5}'|grep /| egrep -v '^/$|/usr|/opt|/var/log|/home|/tmp' output looks like: /filesystem/number1 /filesystem/number2 /filesystem3 /possiblymoreoutput i want the output to look like the below (either in a file or to output to... (3 Replies)
Discussion started by: Tommyk
3 Replies

5. Shell Programming and Scripting

Help with converting Pipe delimited file to Tab Delimited

I have a file which was pipe delimited, I need to make it tab delimited. I tried with sed but no use cat file | sed 's/|//t/g' The above command substituted "/t" not tab in the place of pipe. Sample file: abc|123|2012-01-30|2012-04-28|xyz have to convert to: abc 123... (6 Replies)
Discussion started by: karumudi7
6 Replies

6. Shell Programming and Scripting

Linux - Script to generate the output delimited by Comma/Pipe

Hi All, I have a requirement where I need to go to a directory, list all the files that start with person* (for eg) & read the most recent file from the list of files. While browsing through the forum, i found that the command ls -t will list the files. I am trying to generate the output... (1 Reply)
Discussion started by: dsfreddie
1 Replies

7. Shell Programming and Scripting

How to convert a space delimited file into a pipe delimited file using shellscript?

Hi All, I have space delimited file similar to the one as shown below.. I need to convert it as a pipe delimited, the values inside the pipe delimited file should be as highlighted... AA ATIU2345098809 009697 005374 BB ATIU2345097809 005445 006518 CC ATIU9685098809 003215 003571 DD... (7 Replies)
Discussion started by: nithins007
7 Replies

8. Shell Programming and Scripting

pipe'ing grep output to awk

This script is supposed to find out if tomcat is running or not. #!/bin/sh if netstat -a | grep `grep ${1}: /tomcat/bases | awk -F: '{print $3}'` > /dev/null then echo Tomcat for $1 running else echo Tomcat for $1 NOT running fi the /tomcat/bases is a file that... (2 Replies)
Discussion started by: ziggy25
2 Replies

9. Shell Programming and Scripting

pipe output of grep to sed?

Is there a way I can do this: search for text and replace line containing matched text with a different line? For example: "I want to replace text" I want to search for replace and then change the line to I am perplexed. Hope that makes sense. Thanks in advance. (4 Replies)
Discussion started by: arsh
4 Replies

10. Shell Programming and Scripting

Grep for NULL in a pipe delimited file

hi, How can I check for a field in a pipe-delimited file having a NULL value in Unix using a grep command or any other command. Please reply (5 Replies)
Discussion started by: sureshg_sampat
5 Replies
Login or Register to Ask a Question