Script help needed(lookup 2 text files)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script help needed(lookup 2 text files)
# 1  
Old 08-26-2012
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
PHP Code:
colA        colB        colC    colD
JKU1270A    JKU1042A    9    1
JKU1270A    JKU1042B    9    1
JKU1270A    JKU1042C    9    1
JKU1270B    JKU1107B    9    1
JKU1270B    JKU1107C    9    1
JKU1270B    JKU1090A    9    1
JKU1270X    JKU1042X    9    1
JKU1270X    JKU1042Y    9    1
JKU1270X    JKU1042Z    9    1
JKU1270X    JKU1122X    9    1 
b.txt has
PHP Code:
colA        colB        colC    colD
TOY6055A    JK20CR0R05    60551    4379
TOY6055B    JK20CR0R05    60552    4379
TOY6055C    JK20CR0R05    60553    4379
JKU1270A    JK20CR0R05    51    4412
JKU0005B    JK20CR0R05    52    4412
JKU0005C    JK20CR0R06    53    4412
JKU0005X    JK20CR0R07    57    9884
JKU1270B    JK20CR0R08    58    9884
JKU0005Z    JK20CR0R05    59    9884
JKU0019A    JK20CR0R05    191    4412
JKU1270X    JK20CR0R04    192    4412
JKU0019C    JK20CR0R05    193    4412
JKU0019T    JK20CR0R05    194    587
JKU0019U    JK20CR0R05    195    587
JKU0019V    JK20CR0R05    196    587
JKU0019X    JK20CR0R05    197    9884
JKU0019Y    JK20CR0R05    198    9884
JKU1042A    JK20CR0R06    199    687
JKU1042B    JK20CR0R07    200    612
JKU1042C    JK20CR0R08    201    9720
JKU1107B    JK20CR0R09    202    9884
JKU1107C    JK20CR0R10    203    4412
JKU1090A    JK20CR0R11    204    612
JKU1042X    JK20CR0R12    205    687
JKU1042Y    JK20CR0R13    206    612
JKU1042Z    JK20CR0R14    207    4379
JKU1122X    JK20CR0R15    208    4379 
the output file should be having all columns in a.txt with lookup values of column A, B appended next to it. b.txt has unique values in colA , where as a.txt may have duplicates in colA,colb.
The returning lookup from b.txt is the colD.
The output file should be like this.

PHP Code:
colA        colB        colC    colD    colE(lookup colA)    colF(lookup colB)    colG(check colE=colF)
JKU1270A    JKU1042A    9    1    4412            687            no
JKU1270A    JKU1042B    9    1    4412            612            no
JKU1270A    JKU1042C    9    1    4412            9720            no
JKU1270B    JKU1107B    9    1    9884            9884            yes
JKU1270B    JKU1107C    9    1    9884            4412            no
JKU1270B    JKU1090A    9    1    9884            612            no
JKU1270X    JKU1042X    9    1    4412            687            no
JKU1270X    JKU1042Y    9    1    4412            612            no
JKU1270X    JKU1042Z    9    1    4412            4379            no
JKU1270X    JKU1122X    9    1    4412            4379            no 
Thanks in advance.

Moderator's Comments:
Mod Comment edit by bakunin: how exactly is this "advanced and expert"? You said it yourself: "iam new to unix scripting". Transferring the thread to the "shell programming and scripting" board.

Last edited by bakunin; 08-26-2012 at 06:42 PM..
# 2  
Old 08-26-2012
Have a go with this:

Code:
awk '
    FNR == NR { table[$1] = $4; next; }
    { printf( "%s\t%s\t%s\t%s\n", $0, table[$1], table[$2], table[$1] == table[$2] ? "yes" : "no" ); }
' b.txt a.txt

yes, the filenames are listed in reverse order (b then a).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Needed shell script to append desired text to each line in a file

Hi, I had generated a report in my tool as followsoutput.txt 43.35 9 i needed the script to generate a new file like below i want to append the text to each of these lines of my filenewoutputfile.txt should be Total Amount : 43.35 Record Count:9 Regards, Vasa Saikumar. ... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

3. Shell Programming and Scripting

Hostname lookup and create text file

I have a list of hostnames in a txt file . I need to do nslookup or other command on linux and get the ip address and if you dont find an ip address then put 0.0.0.0 instead in the output text file along with the hostname. So input host1 host2 host2.dd.ddd.net Output host1,... (2 Replies)
Discussion started by: gubbu
2 Replies

4. Shell Programming and Scripting

Some scripts for text files needed

Hi, does anyone have some of those scripts or maybe have idea how to make them? ------------------------------------ 1) block of text multiplication n times: e.g. something1 something2 something3 something4 something5 something6 result: something1 something2 something3 something4... (2 Replies)
Discussion started by: spuzh
2 Replies

5. Shell Programming and Scripting

Help needed in formatting script files

Hi, Can anyone tell me how i can convert all tab spaces inside a script to 4 spaces through another script. Also i need to find if all the quotes are matching and ended properly. Any idea whould be of great help. Many thanks! (3 Replies)
Discussion started by: justchill
3 Replies

6. Shell Programming and Scripting

Shell Script Needed to Read a text from a list files

Hi, Below is my issue which I desperately need and I want a shell script which can do this job. I need this script as I m planning to put this for a system health check. Please assist me. 1. There are 10 log files in a particular location. 2. open each log file. Goto to the end of the... (4 Replies)
Discussion started by: kashriram
4 Replies

7. Shell Programming and Scripting

URGENT: Script/Function needed to read text property files in block wise

Hi, Iam in a need for a script/function in KSH where I want to read a text file (property file) in block by block. Here is the example: Heading Name Descripton Block Block1 Value1 Description Property Name Value Property Name Value Property Name Value Property Name Value Property Name... (7 Replies)
Discussion started by: ysreenivas
7 Replies

8. 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

9. Shell Programming and Scripting

script needed for listing files

hi, i have a the direcories like usr\clone1\heap001.txt usr\clone2\heap334.txt usr\clone3\heap8899.txt i nead a command which list all the file starting with heap*.i have to execute the command from usr directory. find command is hanging, i need some other form of script to do ... (2 Replies)
Discussion started by: jayaramanit
2 Replies

10. UNIX for Dummies Questions & Answers

getting particular text after grep from lookup file

Hi I have two files a1 and b1 a1 has the following job names ab cd ef b1 has the following job details /*----------- ji -----------------*/ asdasd fgd saas dfdf asas fd gfg /*---------- ab ----------------*/ ara jhk dfhk asjla condition: s(abc_wf_hi) (10 Replies)
Discussion started by: napolayan
10 Replies
Login or Register to Ask a Question