awk - replacing stings in file1 with column1 in file2
Hello,
I've never used awk before, but from what I've read, it will best suit what I'm trying to do. I have 2 files. I need to replace strings in file1 with the first column of a matching string in file2. Below are examples:
you are doing it correctly..
you are not getting any errors right??
and are you sure that file contents are same as you given in your question.. i mean no special character and all.
Any string in file 2 that had spaces (AA BC, DDF SCC) did not work for obvious reasons. I've regenerated file 2 to look like this now with sed:
DD:3213
CCA:1231
AA BC:1112
ADFDFF:1232
DDF SCC:2131
Is there any way I can use the awk script you gave me to recognize the columns separated by the colon? I can change the colon to any other value as well if there is something that will work better with awk.
Thanks for the help and patience.
---------- Post updated at 01:39 AM ---------- Previous update was at 01:18 AM ----------
Trying to use awk to:
update $2 in file2 with the $2 value in file1, if $1 in file1 matches $13 in file2, which is tab-delimeted. The $2values may already be the same so in that case nothing happens and the next line is processed.
There are exactly 4,605 unique $13 values. Thank you :).
... (4 Replies)
I am trying to use awk to find all the $2 values in file2 which is ~30MB and tab-delimited, that are between $2 and $3 in file1 which is ~2GB and tab-delimited.
I have just found out that I need to use $1 and $2 and $3 from file1 and $1 and $2of file2 must match $1 of file1 and be in the range... (6 Replies)
Dear All,
Need your help..:D
I am not regular on shell scripts..:(
I have 2 files..
Content of file1
cellRef 4};"4038_2_MTNL_KALAMBOLI"
cellRef 1020};"4112_3_RAINBOW_BLDG"
cellRef 134};"4049_2_TATA_HOSPITAL"
cellRef 1003};"4242_3_HITESH_CONSTRUCTION"
cellRef... (6 Replies)
I have 2 files with 7 fields and i want to print the lines which is present in file1 but not in file2 based on field1 and field2.
Logic: I want to print all the lines, where there is a particular column1 and column2. And we do not find the set of column1 and column2 in file2.
Example: "sc2/10... (3 Replies)
I have file 1 & file 2 with content mentioned below. I want to get the output as shown in file3.
Requirement:
check the content of column 1 & column 2, if value of column 1 in file1 matches with first column of file2 then remaining columns(2&3) of file2 should get replaced, also if value of... (4 Replies)
I have very limited coding skills but I'm wondering if someone could help me with this. There are many threads about matching strings in two files, but I have no idea how to add a column from one file to another based on a matching string.
I'm looking to match column1 in file1 to the number... (3 Replies)
I'm trying to compare two files using AWK, where if field2 of both files match, replace field1 of file1 with field1 of file2 and if there is no match just print the line of file1.
file1.txt (has empty first field)
:ABBATOM:B:H:1992
:ABBA TROJAN:B:H:1993
:ABBES FIRST HOPE:B:M:1997
:ABBEYS... (4 Replies)
I am trying to automate a process of searching through a set of files and replace all occurrences of a formatted text with the next item in the list of a second file. Basically i need to replace all instances of T????CLK???? with an IP address from a list in a second file. the second file is one IP... (9 Replies)
I have an Awk string-compare problem and have searched the internet and forums for a solution i could use but cannot find a solution i understand to make work with my particular problem:
I need to compare (field1 field2 field3 of File1) against (field1 of File2) and if they match print out... (6 Replies)