i am aware of this doable by sed but only limited to one string let me explain let better, lets say in file 1 we got something like this


and in the second file file


so if a string in the second file matches the value in the first it will replace the value in the first file. Note i stink in programming i know this is prrettyy much doable via python or something but im clueless in them

closed as unclear what you're asking by Barmar, Jeff Schaller, countermode, Kusalananda, Mongrel Feb 11 '17 at 10:27

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Easy to do in awk. Read the second file into an array whose keys are the strings you want to match. Then when reading the first file, check if there's a matching array element and perform the replacement. – Barmar Feb 10 '17 at 22:57
  • Or, Barmar's method, but read the first file first, then the second in the same way (allowing the matching keys be replaced in the array) and then write the array at the end. – Ralph Rönnquist Feb 10 '17 at 23:14
  • i almost have no experience in awk, how can it be done? – None111 Feb 10 '17 at 23:34

Assuming you want to replace the first field if the second field matches, then you could use something like this:

awk -F, 'NR==FNR {a[$2]=$1; next} $2 in a {$1=a[$2]} 1' OFS=, file2 file1
  • well it didn't work , its the five field on the first file and the first on the second file, the first file fields are separated by "," – None111 Feb 11 '17 at 11:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.