Refrence File replace (awk)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Refrence File replace (awk)
# 1  
Old 10-29-2013
Refrence File replace (awk)

I know lot of very similar questions have been asked multiple time before ... this is a bit different
Want to replace columns/subcolums from the reference file , if not present in the refrence file leave it as
it is
the complete column does not need to match the refernce file , values within a column also need to be checked .
for example if the column $3 is 10000000c9613e42_10000000c9613f44 , both these values need to be checked .

Input File

Code:
 
`1211,03G:1_12G:1,10000000c9613e42,BL_db00m02d
`1212,03G:1_12G:1,10000000c9613e42_10000000c9613f44,BL_db00m02d
`0DFE,03H:0_12H:0,10000000c974297f_10000000c9742a1a_10000000c9742aa6_10000000c9742ab6,BC_mq00m10_11
`1B02,03H:0_12H:0,10000000c974297f_10000000c9742a1a_10000000c9742aa6_10000000c9742ab6,BC_mq00m10_11

Refrence File
Code:
10000000c9613e42,10000000c9613e42(*)
10000000c9742a1a,10000000c9742a1a(*)
10000000c9742aa6,10000000c9742aa6(*)
10000000c9742ab6,10000000c9742ab6(*)

Output file
Code:
 
`1211,03G:1_12G:1,10000000c9613e42(*),BL_db00m02d
`1212,03G:1_12G:1,10000000c9613e42(*)_10000000c9613f44,BL_db00m02d
`0DFE,03H:0_12H:0,10000000c974297f_10000000c9742a1a(*)_10000000c9742aa6(*)_10000000c9742ab6(*),BC_mq00m10_11
`1B02,03H:0_12H:0,10000000c974297f_10000000c9742a1a(*)_10000000c9742aa6(*)_10000000c9742ab6(*),BC_mq00m10_11

Thanks !
# 2  
Old 10-29-2013
Try:
Code:
nawk -F"," 'NR==FNR{a[$1]=$2;next}{for (i in a) gsub(i,a[i],$0)}1' ref input

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 10-29-2013
Try
Code:
awk 'NR==FNR {REF[$1]=$2; next} {for (X in REF) gsub (X, REF[X])} 1 ' FS="," file2 file1
`1211,03G:1_12G:1,10000000c9613e42(*),BL_db00m02d
`1212,03G:1_12G:1,10000000c9613e42(*)_10000000c9613f44,BL_db00m02d
`0DFE,03H:0_12H:0,10000000c974297f_10000000c9742a1a(*)_10000000c9742aa6(*)_10000000c9742ab6(*),BC_mq00m10_11
`1B02,03H:0_12H:0,10000000c974297f_10000000c9742a1a(*)_10000000c9742aa6(*)_10000000c9742ab6(*),BC_mq00m10_11

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use awk to replace numbers in a file with a column from another file

Hello, I am trying to make a awk code that will take 2 files, a txt file like this : 1 1 88 c(1:38, 42, 102) 2 2 128 c(39:41, 43:101, 103:105, 153, 155:189, 292, 344:369) 3 3 84 c(190:249, 603, 606:607, 609:629) 4 4 12 ... (8 Replies)
Discussion started by: nastaziales
8 Replies

2. UNIX for Dummies Questions & Answers

awk to replace values in one file using a second reference file

Hi, I'd be grateful for your help with the following: I have a file with a single column (file1). Let's say the values are: a b c 5 d I have a second, reference file (ref_file), which is colon-delimited, and is effectively a key. Let's say the values in it are: a:1 b:2 c:3 d:4... (4 Replies)
Discussion started by: aberg
4 Replies

3. Shell Programming and Scripting

Replace from refrence file

Input file FS01,/root_vdm_9/UKSR06_FS01,test1 FS04,/root_vdm_11/UKSR04_FS04,test2 FS01,/root_vdm_7/UKSR02_FS01,test4 FS01,/root_vdm_12/UKSR03_FS01/dhdhdhdh,test5 FS01,/root_vdm_11/UKSR04_FS01/gggg,test6 Reference File /root_vdm_9/UKSR06_FS01,UKSR06_FS01... (2 Replies)
Discussion started by: greycells
2 Replies

4. Shell Programming and Scripting

How to replace first line of every file using awk

How to replace first line of every file with mm200 ? Thanx in advance. file.mail >mm89589585989“”* GGG >HH DG file1.mail >mm454695879357 dg output filemail >mm200 GGG (15 Replies)
Discussion started by: quincyjones
15 Replies

5. Shell Programming and Scripting

Replace from reference file awk

Basically want to replace any field in input file from the refernce file ... for example. clar_2400:3113 in input file will be replaced by clar_2400:3113 Input file field seperator is "," Field which is not found in reference will stay as it is ... Input File ... (3 Replies)
Discussion started by: greycells
3 Replies

6. Shell Programming and Scripting

Search and replace from file in awk using a 16 bit text file

Hello, Some time ago a helpful awk file was provided on the forum which I give below: NR==FNR{A=$0;next}{for(j in A){split(A,P,"=");for(i=1;i<=NF;i++){if($i==P){$i=P}}}}1 While it works beautifully on English and Latin characters i.e. within the ASCII range of 127, the moment a character beyond... (6 Replies)
Discussion started by: gimley
6 Replies

7. Shell Programming and Scripting

Replace from Refrence file

Need help with this .. Input file 234,6006016061302E006BE89E7FD64DE111,6006016061302E00B824FDA6D32CE111,Complete Refrence File 6006016061302E006BE89E7FD64DE111:vvv_222:433:RP_JRNL_LUN_3005 6006016061302E00B824FDA6D32CE111:vvv_444:344:laputa_LUN_95_L If $2 or $3 from input... (1 Reply)
Discussion started by: greycells
1 Replies

8. Shell Programming and Scripting

How to find a certain string in a file and replace it with a value from another file using sed/awk?

Hi Everyone, I am new to this forum and new to sed/awk programming too !! I need to find particular string in file1(text file) and replace it with a value from another text file(file2) the file2 has only one line and the value to be replaced with is in the second column. file 1: (assert (=... (21 Replies)
Discussion started by: paramad
21 Replies

9. Shell Programming and Scripting

How to use refrence values inside sed command

I am using script S_db=`grep SRC_DB= ${login_txt} | cut -d= -f2` T_db=`grep TGT_DB= ${login_txt} | cut -d= -f2` today=`date +%Y%m%d` sed 's/USER_WORK/RAR_WORK_D1/g' < ${my_path}/files/${T_target}_${today}_DDL.txt > ${my_path}/files/temp9 But when I am trying to remove hardcode values... (1 Reply)
Discussion started by: scorp_rahul23
1 Replies

10. Shell Programming and Scripting

Refrence Shell variable in Perl code.

:confused: I have 2 files a & b Contents of a are:- -------------------------- This is a Good Boy This is a Good Boy This is a Very Good Boy This is a Good Boy This is a Good Boy --------------------------- The contents of b are ------------------- This is Testing Beta... (5 Replies)
Discussion started by: send2sridhar
5 Replies
Login or Register to Ask a Question