1833873 Members
2504 Online
110063 Solutions
New Discussion

Re: print for file

 
nightwish
Advisor

print for file

hi

How to print in the bigining of the output of a command the name of the machine ?? ..
The name is easy uname -s but i dont now how to put in the beginig of each line ..

regards ..
7 REPLIES 7
Mel Burslan
Honored Contributor

Re: print for file

Your question is not clear. Could you please clarify with an example ?

what are you trying to print ?
where are you trying to print to ? terminal screen or printer ?
________________________________
UNIX because I majored in cryptology...
Pete Randall
Outstanding Contributor

Re: print for file

Try something like this:

uname -s > file1
cat file2 >> file1
mv file1 file2


Pete

Pete
Peter Godron
Honored Contributor

Re: print for file

Hi,
could you pleas clarify or give example.

For example:
To change the prompt:
export PS1=`uname -n`
To prefix all lines in a file:
sed "1,$ s/^/hostname /" file > file.new
Pete Randall
Outstanding Contributor

Re: print for file

Actually, I would use hostname rather than uname -s.


Pete

Pete
A. Clay Stephenson
Acclaimed Contributor

Re: print for file

Here is one approach capuring the outout of "ls -l /etc":

#!/usr/bin/sh

HOST=$(uname -n)
ls -l /etc | while read X
do
echo "${HOST}: ${X}"
done
If it ain't broke, I can fix that.
nightwish
Advisor

Re: print for file

hi

I already solv my problem whit awk !!

Thanks
Peter Godron
Honored Contributor

Re: print for file

Hi,
if you are happy with the replies, can you please see:
http://forums1.itrc.hp.com/service/forums/helptips.do?#28
and give more info on your solution, so future users can learn.