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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk with printf 1

Status
Not open for further replies.

tektipsaix

Technical User
Mar 4, 2011
31
ZA
Hi all

I want to add a server description to some output. The command should look this up in another file.

$1 is the server_name, and $3 will be the description.

serverlist.txt has 2 columns: server_name and server_location
serverdesc.txt has 2 columns: server_name and server_description

$3 must be looked up from the serverdesc.txt file. How can this be accomplished ?

syntax:
cat serverlist.txt | awk '{ printf("%- 20s %- 20s %- 10s\n", $1, $2, $3); }'

Many thanks!
Jasper
 
Why not simply use the join command ?
Anyway, as you asked in the awk forum:
awk 'NR==FNR{d[$1]=$2;nexr}{printf("%-20s %-20s %-10s\n",$1,$2,d[$1]}' serverdesc.txt serverlist.txt

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PH

Fantastic..!

Many thanks for your reply. I only had to replace "nexr" with "next" and added a closing ")".

Jasper
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top