Help on lookup script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help on lookup script
# 1  
Old 04-10-2013
Help on lookup script

Hi All,

I've had a look around the forum but cannot find any answers for what I want to do.

I have 2 files :

FILE 1
===============
Code:
ter049107
ter049048
2013-04-09 08:15:16
ter049056
ter049083
ter049112
2013-04-09 10:35:10
2013-04-09 10:29:47
2013-04-09 07:44:05

FILE 2 - note the space is tab seperated
==================
Code:
ter049048 Dave
ter049056 Robert
ter049083 John
ter049112 Tom
ter049107 Bob

Output Required
==================
Code:
ter049107 - Bob
ter049048 - Dave
2013-04-09 08:15:16
ter049056 - Robert
ter049083 - John
ter049112 - Tom
2013-04-09 10:35:10
2013-04-09 10:29:47
2013-04-09 07:44:05

I've been trying it with Awk but can't get it to work correctly.
Any help would be very appreciated.

Thanks
P

Last edited by Franklin52; 04-11-2013 at 03:23 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 04-10-2013
Where are you stuck with your code? May be we can help you correct it.

--ahamed
# 3  
Old 04-10-2013
This is what I've been trying :

Code:
awk 'NR==FNR{a[$1$3]=$0;}{print a[$1$2],$3;}' FILE2 FILE1

The output I get omits the time/date stamp and if using long name like John Smith then it lists Smith in a prior entry and then John.
# 4  
Old 04-10-2013
Try this
Code:
awk 'NR==FNR{x=$1;sub(x,"");a[x]=$0;next}a[$1]{print $1" -"a[$1];next}1' FILE2 FILE1

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 5  
Old 04-10-2013
Worked like a charm! Smilie

Thank you.

P
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with Shell Script: User Lookup

Hi everyone, Let me start by stating this question is for homework help (not "help, my boss needs this ASAP") I have spent the last few days re-visiting this script, and cannot figure out where I am going wrong (something simple I'm sure). I am to build a script that searches for a user... (1 Reply)
Discussion started by: jjc032681
1 Replies

2. Shell Programming and Scripting

Bash script to replace text file from a lookup file

Hi. I need assistance with the replacing of text into a specific file via a bash script. My bash script, once run, currently provides a menu of computer names to choose.The script copies onto my system various files, depending what computer was selected in the menu.This is working OK. Now, I... (1 Reply)
Discussion started by: jonesn2000
1 Replies

3. Shell Programming and Scripting

IP Address LookUp Bash Script

I am new to bash scripting. I want write a script that reads from the first argument file and run nslookup, then prints out each nslookup. Something like below: File name = ip 8.8.8.8 8.8.4.4 Bash shell script: nslookup.sh #!/bin/bash for i in $1 do nslookup $i done I... (7 Replies)
Discussion started by: boldnbeautiful
7 Replies

4. Shell Programming and Scripting

Script help needed(lookup 2 text files)

Hi, iam new to unix scripting need a help. The scenario is i have 2 text files. a.txt has colA colB colC colD JKU1270A JKU1042A 9 1 JKU1270A JKU1042B 9 1 JKU1270A JKU1042C 9 1 JKU1270B JKU1107B 9 1 JKU1270B JKU1107C 9 1... (1 Reply)
Discussion started by: tech_frk
1 Replies

5. Shell Programming and Scripting

lookup script

dear all.. need your help.. i have searching but still didn't find what i need. i have 2 file, i want to lookup one to many, the key is $1 : main.txt code.txt output.txt thanks.. br, herman (2 Replies)
Discussion started by: buncit8
2 Replies

6. Shell Programming and Scripting

variable lookup problem in shell script

Hi I have one properties file containing as $INSTALL_BASEPATH/mssages/commonmessages_default.properties $INSTALL_BASEPATH/resource/configurationBundle.properties and $INSTALL_BASEPATH is set in .bash_profile but from shell script when I read this file and use in copy statement then it... (7 Replies)
Discussion started by: mnmonu
7 Replies

7. UNIX for Advanced & Expert Users

Clueless about how to lookup and reverse lookup IP addresses under a file!!.pls help

Write a quick shell snippet to find all of the IPV4 IP addresses in any and all of the files under /var/lib/output/*, ignoring whatever else may be in those files. Perform a reverse lookup on each, and format the output neatly, like "IP=192.168.0.1, ... (0 Replies)
Discussion started by: choco4202002
0 Replies

8. Shell Programming and Scripting

whois lookup from script intermittently not working

Hello, I wrote a basic script to query a whois server using the whois system command to retrieve information about IP's. I have file containing the ip addresses which I feed to the whois command via a while loop. This seems to work sometimes. Most of the time, the whois command seems not to... (0 Replies)
Discussion started by: aliberson
0 Replies

9. Shell Programming and Scripting

lookup script

hello I am a student taking an intro to UNIX class. I have an assignment I am having trouble completing. The assignment is as follows. i have a file called .addr_book that has various names and phone numbers in it. I need to write a script called lookup that will run like this I... (2 Replies)
Discussion started by: tampaJim
2 Replies

10. Shell Programming and Scripting

Getting a script to find another script via lookup service

Hi, I'm trying to write a basic script which will measure throughput at a node on a network, and pass the results on to a manager script (running on another node on the same network). I presume that I need to use some sort of naming service, so that the manager can publish its location. From what I... (2 Replies)
Discussion started by: zeppelin147
2 Replies
Login or Register to Ask a Question