Pattern Matching and replacement

Hello Everybody,

I need a help in the below pattern matching and replacement issue
I have a file : emp.txt

21356 suresh 12/12/2012
23511 ramesh 11/06/2011
31456 biswajit 09/08/2013
53134 archan  06/02/2009

first field:- employee id, 2nd field is name and third field is date of joining

HR gives a list of employees who have been moved out of the company.
Let's suppose i get a text file from hr:-

ramesh
archan

I need to compare it with second column of the original employee list and which ever matches , employee list will be updated

output file

21356 suresh 12/12/2012
23511 ramesh_terminated  11/06/2011
31456 biswajit 09/08/2013
53134 archan_terminated  06/02/2009

Thanks

Is this a homework assignment?

What have you tried?

What OS and shell are you using?

No this is not a home work assignment. I am not able to figure it out at all.
I am using bash shell and linux operating system

Please show us what you have tried so far.

Use it & let me know if it is working fine for you:

file="tmp.txt"   ### this is your input file with all the records
pat_file="term.txt"   ### this is your pattern file.

while read pat_line
do
        sed -i "s/$pat_line/${pat_line}_teminated/g" $file

done < "$pat_file"

Use it & let me know if it is working fine for you:

file="tmp.txt" ### this is your input file with all the records
pat_file="term.txt" ### this is your pattern file.

while read pat_line
do
sed -i "s/$pat_line/${pat_line}_teminated/g" $file

done < "$pat_file"
kibou@laptop:~$ cat text.txt 
21356 suresh 12/12/2012
23511 ramesh 11/06/2011
31456 biswajit 09/08/2013
53134 archan  06/02/2009
kibou@laptop:~$ sed 's;\(ramesh\);\1_terminated;' text.txt 
21356 suresh 12/12/2012
23511 ramesh_terminated 11/06/2011
31456 biswajit 09/08/2013
53134 archan  06/02/2009

Use it & let me know if this works for you:

file="tmp.txt"   ### file to search & replace employees
pat_file="term.txt"   ### file containing pattern

while read pat_line
do
        sed -i "s/$pat_line/${pat_line}_teminated/g" $file

done < "$pat_file"

Hello,

one more approach for same may help.

awk 'NR==FNR{a[$1]=$0;next}  !($2 in a){b[i++]=$0} ($2 in a){{$2=$2"_term";b[i++]=$0}} END{for(j in b){print b[j]}}' test2 test1

output will be as follows.

21356 suresh 12/12/2012
23511 ramesh_term 11/06/2011
31456 biswajit 09/08/2013
53134 archan_term 06/02/2009

Where input files are as follows.

cat test1
21356 suresh 12/12/2012
23511 ramesh 11/06/2011
31456 biswajit 09/08/2013
53134 archan  06/02/2009

cat test2
ramesh
archan

Thanks,
R. Singh

Please, no posts untils OP has replied to moderator request!
Previous posts of R. Singh and Krishna Yadav are in moderation queue till OP replies...

I am a beginner and i am learning. I will get back on this,when i learn enough to write it.

Please no more replies to this thread. Moderator can close this thread if they feel necessary.