Script to multiple find and replace in a single file

Dear all

I need a script for multiple find and replace in a single file.
For example input file is -

qwe wer ert rty tyu
asd sdf dgf dfg fgh
qwe wer det rtyyui
jhkj ert asd asd dfgd

now

qwe should be replace with aaaaaa
asd should be replace with bbbbbbbb
rty should be replace with cccccc
tyu should be replace with uuuuu

There are more than 500 find and replace command. Please help me.

sed search and replace ... should be easy ...

I believe the find and replace commands are recorded in a file : How does it look like?

Create a reference file like:

qwe aaaaaa
asd bbbbbbbb
rty cccccc
tyu uuuuu

and try this command:

awk 'NR==FNR{a[$1]=$2;next} {
  for(i=1;i<=NF;i++) {
    if(a[$i]){$i=a[$i]}
  }
}1' referencefile mainfile
1 Like

How? please explain?

Look at Franklin52 's post above...

Thank you Franklin52

its working