1

I want to replace the contents of each line of a file with each line of another file in Unix.

filetxt     keytxt
abc         pqr
def         uvw

Here abc should be replaced with pqr and def should be replaced with uvw.

closed as unclear what you're asking by Jeff Schaller, Wildcard, countermode, grochmal, strugee Feb 24 '17 at 2:48

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.

  • 9
    you don't need sed for this: cp keytxt filetxt unless it's more complex than that in which case you should edit the question and add the details... – don_crissti Feb 23 '17 at 18:50
  • Do you mean replace the whole file with the other? – Emilio Galarraga Feb 23 '17 at 18:51
-1

You can use awk command but it will swap the text with each other. e.g.
paste first_file 2nd_file | awk '{print $2" " $1}' $2 represents second line and $1 represents first

  • Um, do you have details on how to do that, or ... ? – thrig Feb 23 '17 at 23:58
  • your comment should be edited in to your answer to make the Answer more complete – Jeff Schaller Feb 24 '17 at 0:09
  • I want that wherever abc is present in filetxt it should find it till the end of that file and then it should be replaced with the pqr which is present in keytxt and same with the other strings present in filetxt . – user217679 Feb 25 '17 at 10:22
  • can we use a loop for this. – user217679 Feb 25 '17 at 10:24

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