I have multiple sets of files, so I greped the list from column in seperate file such as file1.txt. I want to change all other file by using this file1.txt based on matching string. for example I am pasting three file here File 1 chr - seq1 NZ_JAHWGH010000010.1 0 60562 green_a4 chr - seq3 NZ_JAHWGH010000012.1 0 466573 green_a4 chr - seq5 NZ_JAHWGH010000013.1 0 125526 green_a4 chr - seq39 NZ_CAJGBF010000006.1 0 211154 green_a4 chr - seq40 NZ_CAJGBF010000007.1 0 199119 green_a4 chr - seq41 NZ_CAJGBF010000008.1 0 190934 green_a4 chr - seq42 NZ_CAJGBF010000009.1 0 178251 green_a4 I extracted required information using grep, command is given below grep "NZ_JAHWGH" file.txt |awk '{print $3}' >file1.txt grep "NZ_CAJGBF" file.txt |awk '{print $3}' >file2.txt Now I wanted to use this file1.txt and file2.txt to change in another files. Output will be like if list in file1.txt match then all matched list should be substitued as seq1 similarly using second file2.txt I want to substitue all matching pattern as seq2. for example file is given here to be changed by using information from previous file seq3 19301 20914 fill_color=green_a0 seq1 16726 18337 fill_color=green_a0 seq5 167934 169650 fill_color=green_a0 seq42 200621 202367 fill_color=red_a0 seq41 160164 161903 fill_color=green_a0 seq40 31356 33104 fill_color=green_a0 and final output after changed should be as follows seq1 19301 20914 fill_color=green_a0 seq1 16726 18337 fill_color=green_a0 seq1 167934 169650 fill_color=green_a0 seq2 200621 202367 fill_color=red_a0 seq2 160164 161903 fill_color=green_a0 seq2 31356 33104 fill_color=green_a0 I tried using this command for i in f2.txt; do grep -wf f1.txt $i|awk '{$1="seq1";print}'; grep -wf other.txt $i |awk '{$1="seq2";print}'; done Is this correct if correct is there any more efficient way to do it appreciate yout time and help