|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|