Operating System - HP-UX
1833151 Members
3679 Online
110051 Solutions
New Discussion

Placing text before command output

 
SOLVED
Go to solution
Jeffrey S. Bromley
Occasional Contributor

Placing text before command output

Does anyone know how to place text before the output of a command? Basically, what I am trying to do is run a 'bdf', and then format the output like:

Server Name: /dev/vg00/lvol1 kbytes used avail
The only easy day was yesterday
4 REPLIES 4
Mark van Hassel
Respected Contributor
Solution

Re: Placing text before command output

Hi,

bdf | while read line
do
echo "`hostname` : $line"
done
The surest sign that life exists elsewhere in the universe is that none of it has tried to contact us
Rodney Hills
Honored Contributor

Re: Placing text before command output

sed probabily would work the best

bdf | sed -e 's/^/server:/' >resultfile.txt
There be dragons...
A. Clay Stephenson
Acclaimed Contributor

Re: Placing text before command output

Hi Jeffrey:

Depending on what you want to do the number od methods is legion.

1) echo "Server Name: \c"
bdf

2) HNAME=`hostname`
bdf | awk -v host=${HNAME} '{print "Server Name: ",host," ",$0}'

3) You could use paste to combine two files

Just a few, Clay
If it ain't broke, I can fix that.
Jeffrey S. Bromley
Occasional Contributor

Re: Placing text before command output

Thanks for all the prompt replies. It is really appreciated
The only easy day was yesterday