Reputation: 87
Hi I am trying to search a very large .txt file for specific strings in one column of the file found in a separate .txt file.
Depending on whether the string is found/or not in the specified column, I would then like to add another string to a separate column.
For example:
Input file:
ID data name Yes_No
1 225 name1
2 245 name2
3 355 name3
4 466 name4
5 230 name5
File2:
ID
1
3
5
Desired output:
ID data name Yes_No
1 225 name1 1
2 245 name2 0
3 355 name3 1
4 466 name4 0
5 230 name5 1
I am hoping this will be straight forward, but I have become stuck! I would greatly appreciate some help.
Thanks
Upvotes: 0
Views: 51
Reputation: 195289
This may help:
awk 'NR==FNR{a[$1]=1;next}FNR>1{$4=0+a[$1]}7' file2 file1
If you want to get a better format, you can pipe the result to |column -t
Upvotes: 2