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 screen i dont mind):

/filesystem/number1|/filesystem/number2|/filesystem3|/possiblymoreoutput

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)

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

Tommyk,

adding some extra code to your code

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

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 :slight_smile: