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!

How to create columns from output of 2 files

Status
Not open for further replies.

jeffg2235

IS-IT--Management
Jul 25, 2008
3
I am a beginner with awk, trying to create a snmp script that will pull data from each snmp MIB which is dumped to a file. iam printing column 4 from each file which has relevant data.

what i am trying to achieve is this:
examples below
file1
10.1.1.1
10.2.2.2

file2
app1
app2

output desired:

10.1.1.1 app1
10.2.2.2 app2


#!/bin/bash
server=x.x.x.x
community=yyyyyy


/usr/bin/snmpwalk -c $community -v 1 $server .1.3.6.1.4.1.1991.1.1.4.2.1.1.2 > product
/usr/bin/snmpwalk -c $community -v 1 $server .1.3.6.1.4.1.1991.1.1.4.2.1.1.3 > ips
awk -F"," '{ print $4 }' product > products && awk -F"," '{ print $4 }' ips > ip1

paste products ips | awk -F, '{ printf("%-20s%-20s\n",$1,$2 )}'
 
Replace this:
paste products ips
with this:
paste products ip1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The problem still remains I have not been able to have the two outputs on the same line.

ip1 was supposed to contain output of awk reading column 4 but it didnt do it. I also read the man pages for paste and merge and tried samples of each but i keep getting the output of both snmp commands on top of each other instead of in columns. I will try a few more things tomorrow and update this page with my most recent changes.

thanks for everyones help so far
 
/usr/bin/snmpwalk -c $community -v 1 $server .1.3.6.1.4.1.1991.1.1.4.2.1.1.2 > product
/usr/bin/snmpwalk -c $community -v 1 $server .1.3.6.1.4.1.1991.1.1.4.2.1.1.3 > ips

awk ' { print $4 }' product > product4
awk ' { print $4 }' ips > ips4

paste product4 ips4 | awk '{printf("%-20s%-20s\n", $1, $2)}'


using patse with awk gives me the desired output thanks all
 
Another way:
Code:
/usr/bin/snmpwalk -c $community -v 1 $server  .1.3.6.1.4.1.1991.1.1.4.2.1.1.2 > product
/usr/bin/snmpwalk -c $community -v 1 $server  .1.3.6.1.4.1.1991.1.1.4.2.1.1.3 > ips
awk 'NR==FNR{p[NR]=$4;next}{printf "%-20s%-20s\n",p[FNR],$4}' product ips

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top