Modifications using Lookup file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Modifications using Lookup file
# 1  
Old 11-07-2012
Modifications using Lookup file

I have 2 files. File 1 delimited by ";"

File 1:
Code:
001;0;11223;xx;N;1001051;124;1;1;1001051;110;0;A_15;D;DX;U
001;0;8830943;xx;P;1226040;978;1;0;1226040;110;0;A_15;D;DX;H
001;0;10946903;xx;N;1300496;978;1;1;1300496;110;0;A_17;D;DX;H
001;0;10954168;xxt;P;1305274;978;1;0;1305274;220;0;A_13;D;DX;H

File 2:
Code:
1001051
1012427
1300496
2018181
1002418

Now for each record in File2, if found in 6th position of File 1, replace the 12th Position to "R" to look like


Code:
001;0;11223;xx;N;1001051;124;1;1;1001051;110;R;A_15;D;DX;U
001;0;8830943;xx;P;1226040;978;1;0;1226040;110;0;A_15;D;DX;H
001;0;10946903;xx;N;1300496;978;1;1;1300496;110;R;A_17;D;DX;H
001;0;10954168;xxt;P;1305274;978;1;0;1305274;220;0;A_13;D;DX;H

Thanks for the help.
# 2  
Old 11-07-2012
Code:
awk -F';' 'NR==FNR{a[$0];next} $6 in a {$12="R"}'1 OFS=';' file2 file1

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 11-07-2012
Thanks balajesuri. Works perfectly fine. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Lookup value from another file

Hi Experts, I need you help in coding the below scenario in unix. Please help Lets say i have below 2 records in my file1 a;b;c a;d and in file 2 , i have the below information a:alpha b:beta c:code d:delta then i want to lookup on file2 and replace my content in file... (2 Replies)
Discussion started by: ashishagg2005
2 Replies

2. UNIX for Dummies Questions & Answers

Help with AWK - Compare a field in a file to lookup file and substitute if only a match

I have the below 2 files: 1) Third field from file1.txt should be compared to the first field of lookup.txt. 2) If match found then third field, file1.txt should be substituted with the second field from lookup.txt. 3)Else just print the line from file1.txt. File1.txt:... (4 Replies)
Discussion started by: venalla_shine
4 Replies

3. Shell Programming and Scripting

Modifications to a file

I have a file whose format is shown below. It has a table of numbers. In this case, I have 16 values in 12 rows. I want to select a position in the table, example, the 5th number at row 5. I need to change the value in that position by a certain amount and output the file with the modifiation. ... (6 Replies)
Discussion started by: kristinu
6 Replies

4. Shell Programming and Scripting

Modifications to a file

Hi, I do not have a clue how to do this nor can I find information on it but I have a file that looks like this (basically 3 columns and tab delimited). I need this in a particular format in order for a program to actually read it. chr1 2 4 chr1 2 5 chr1 3 6 chr2 1 4 chr2 2 5 ... (2 Replies)
Discussion started by: kylle345
2 Replies

5. Shell Programming and Scripting

XML file modifications using sed

Hi, During an installation process in a bash script I need to do 2 things with 2 XML files. Does the use of sed affect in any way the XML file ? 1.Add to a section in <ServerListeners> section <ServerListener> <BaseClass>myapp.module.WowConfigurator</BaseClass> </ServerListener> The... (2 Replies)
Discussion started by: potro
2 Replies

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

7. Shell Programming and Scripting

my shell script (file modifications)

hi guys Need some help on my below script #!/bin/sh if then echo "~~:S:wait:/sbin/sulogin" >> /root/joy/inittab else echo "/root/joy/inittab does not exist" fi now the problem is that when i run the above script it runs successfully but when i run it repeatedly the word echo... (2 Replies)
Discussion started by: whizkidash
2 Replies

8. UNIX for Advanced & Expert Users

Tracing file modifications

Hello all! Is there a way or a utility to trace any kind of file changes in a particular directory on any UNIX machine? The purpose is that in Unix, there are multiple ways of opening and making changes to a file. But internally, there must be something common (a single pipe, etc.) that is... (3 Replies)
Discussion started by: gupta_ca
3 Replies

9. UNIX for Dummies Questions & Answers

file lookup

I need to do a text lookup for multiple records against a file that contains a key and two results. I found this code: str=`awk '$1 == search' search=$1 lkup.tbl It's a little tricky because the first $1 is the key variables location in the lkup.tbl and the second $1 is the parameter passed... (6 Replies)
Discussion started by: gillbates
6 Replies

10. Shell Programming and Scripting

In Line File Modifications: Search and Replace

grep -il "TEST" ${ENVIRON}/*.pde| while read pde &nbsp;&nbsp;do &nbsp;&nbsp;&nbsp;&nbsp;cat $pde | sed s/"TEST 3,1"/"TEST 3,0"/g | sed s/"TEST&nbsp;&nbsp;3,1"/"TEST&nbsp;&nbsp;3,0"/g > ${pde}.tmp &nbsp;&nbsp;&nbsp;&nbsp;if ; then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mv ${pde}.tmp $pde ... (2 Replies)
Discussion started by: Shakey21
2 Replies
Login or Register to Ask a Question