I want to display the output of the following commands which are as below-:
1)
mount | grep -i "/dev/sd*" | awk '{ print NR "\t" $1 "\t" $3 }'
2)
/usr/sbin/smartctl -a /dev/sdb | grep Device: | awk '{print $2 }'
The 1st comand displays 3 columns with multiple rows and the next command displays one one column of information.
I want to concat the outputs of both the commands and concat and display as 4 columns with multiple rows. Please suggest.
In Bash, we can use both “{ }” and “( )” operators to group commands.
Putting a comma on the end of the print() line prevents print() from issuing a new line (you should note that there will be an extra space at the end of the output). It works perfectly.
This is what paste
is for. Use process substitution to make the shell treat your commands like files:
paste <(mount | awk 'tolower($0) ~ /\/dev\/sd*/ {print NR "\t" $1 "\t" $3}') \
<(/usr/sbin/smartctl -a /dev/sdb | awk '/Device:/ {print $2}')
I removed the grep commands, which awk can easily do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With