find from file and replace with specific text

Dear All,

I do not have any knowledge of scripting. I want to replace specific lines of a text file with a specific text. Like I have one file which is "original file" and one file "changes file" which has list of lines which I want to replace in original file with a specific string. I want the script to go through the original file using changes file line by line and change the text as soon as it finds it with the given text and after first occurrence should move to the next line of the changes file and look for the second line and change it with the same given text. the lines in the changes file are kept sequentially in the same order as the original file so the pointer do not need to go back up. Please help. Thanks in advance.

cat old_file | sed 's/one/two/g' > new_file

Please post an example of both files where we can see by which key/criteria the replacement should be done.
Please use

```text
 and 
```

tags for better readability of the examples, thanks.

@pamu:
You can leave that cat out. It is not needed since sed like many other tools can read files on their own; example:

sed 's/one/two/g' old_file > new_file

I will try to explain with following example.

original_file

a@b.com
c@d.com
E@f.com
g@h.com
i@j.com
k@l.com

change_file

c@d.com
i@j.com

I want to change the contents of original_file that matches contents of change_file with specific text like x@x.com
After running the query the resulting file should look like following

New_file

a@b.com
x@x.com
E@f.com
g@h.com
x@x.com
k@l.com

I hope this explains my requirement. Thanks alot for all the support.

try this

awk -v val="x@x.com" 'NR==FNR{a[$1]++;next}
a[$1]{$0=val}1' changeFile origfile
1 Like

Thanks alot, it worked like magic.