Pipe delimited output | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Pipe delimited output

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-16-2013
Tommyk Tommyk is offline
Registered User
 
Join Date: Aug 2011
Last Activity: 22 August 2014, 10:29 AM EDT
Location: Ripon, North Yorkshire
Posts: 146
Thanks: 4
Thanked 14 Times in 14 Posts
Pipe delimited output

Hi All,

i have the following command


Code:
df|awk '{print $5}'|grep /| egrep -v '^/$|/usr|/opt|/var/log|/home|/tmp'

output looks like:


Code:
/filesystem/number1
/filesystem/number2
/filesystem3
/possiblymoreoutput

i want the output to look like the below (either in a file or to output to screen i dont mind):

Code:
/filesystem/number1|/filesystem/number2|/filesystem3|/possiblymoreoutput

Sponsored Links
    #2  
Old 01-16-2013
Scott's Avatar
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 18 September 2014, 3:11 PM EDT
Location: Zürich
Posts: 8,482
Thanks: 331
Thanked 1,046 Times in 913 Posts
You could add paste -sd\| to the end of your command.

You could also combine all of that into a single awk with ORS=\|

For example (my df is slightly different to yours, so the command is different too)


Code:
$ df -hP | awk '$6 ~ /^\/opt$|^\/usr$/ { print $6 }' ORS=\|
/opt|/usr|


Last edited by Scott; 01-16-2013 at 07:01 AM.. Reason: Actually, it's probably the same df, just I've used the -h -P options!
The Following User Says Thank You to Scott For This Useful Post:
Tommyk (01-16-2013)
Sponsored Links
    #3  
Old 01-16-2013
srinivas matta srinivas matta is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 21 February 2013, 2:05 AM EST
Location: Hyderabad
Posts: 30
Thanks: 0
Thanked 8 Times in 8 Posts
Tommyk,

adding some extra code to your code


Code:
df|awk '{print $5}'|grep /| egrep -v '^/$|/usr|/opt|/var/log|/home|/tmp'| sed -e :a -e 'N;s/\n/|/; ta'


Last edited by Scott; 01-16-2013 at 07:27 AM.. Reason: Use code tags, please...
The Following User Says Thank You to srinivas matta For This Useful Post:
Tommyk (01-16-2013)
    #4  
Old 01-16-2013
Tommyk Tommyk is offline
Registered User
 
Join Date: Aug 2011
Last Activity: 22 August 2014, 10:29 AM EDT
Location: Ripon, North Yorkshire
Posts: 146
Thanks: 4
Thanked 14 Times in 14 Posts
Cheers guys, both paste and sed work a treat, although my lack of awk understanding i just get syntax errors and unexpected newline or end of string, im working on learning awk so hopefully in time i wont have to ask these simple questions. Never seen the paste command before though
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help with converting Pipe delimited file to Tab Delimited karumudi7 Shell Programming and Scripting 6 02-01-2012 04:55 AM
Linux - Script to generate the output delimited by Comma/Pipe dsfreddie Shell Programming and Scripting 1 01-22-2012 10:30 PM
How to convert a space delimited file into a pipe delimited file using shellscript? nithins007 Shell Programming and Scripting 7 09-25-2011 05:33 AM
convert a pipe delimited file to a':" delimited file priyanka3006 Shell Programming and Scripting 6 05-26-2009 10:53 AM
How to split pipe delimited file njgirl Shell Programming and Scripting 4 06-18-2008 05:15 PM



All times are GMT -4. The time now is 03:45 PM.