Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cat with grep and or awk 1

Status
Not open for further replies.

tjbradford

Technical User
Dec 14, 2007
229
GB
Hi all i am greping a file to obtain the hostname and ip address

cat file.txt |grep -e "hostname" >made.txt
cat file.txt |grep -e "ip address" >>made.txt

file then contains the following

hostname device-1
ip address 10.10.10.1
ip address 10.10.10.2
ip address 10.10.10.3

i would like it in this format ideally

hostname device-1 ip address 10.10.10.1
hostname device-1 ip address 10.10.10.2
hostname device-1 ip address 10.10.10.3

what magic do i need to do this?

I am looking to do this on a windows box really but with qgrep and gawk - if needs must tho i can do it on a linux box but the files are on dows at the moment.

any ideas
 
Try this:

Code:
awk '/hostname/ {h=$0} /ip address/ { print h,$0 }' file.txt > made.txt

Annihilannic.
 
10 print "many thanks"
20 goto 10

run


Perfect thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top