huang cheng huang cheng - 7 months ago 50
Bash Question

bash shell-How to swift a file specific content with another file after a match pattern found

>cat file1.txt
aa bb
ccc dd
ee fff
>cat file2.txt
1
2
3


I want to get the result like below:

aa1bb
ccc2dd
ee3fff


The space in file1.txt will be replaced by number in file2.txt.

Answer Source

with a bash while-read loop

while read -u3 a b; read -u4 n; do 
    echo "$a$n$b"
done 3<file1.txt 4<file2.txt
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download