Tommyk
January 16, 2013, 6:42am
1
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
Scott
January 16, 2013, 6:45am
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)
$ 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
Tommyk
January 16, 2013, 7:55am
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