我正在尝试写一个bash脚本,它将执行以下操作:
>从第一个文件读取内容(作为第一个参数)
>从第二个文件读取内容(作为第二个参数)
>使用给定模式找到第二个文件中的行(作为第三个参数)
>将文本从第一个文件插入到第二个文件的模式行之后.
>在屏幕上打印最终文件.
例如:
first_file.txt:
111111
1111
11
1
second_file.txt:
122221
2222
22
2
模式:
2222
122221
111111
1111
11
1
2222
111111
1111
11
1
22
2
在BASH上实现此功能应该怎么用?
我写的代码,但它不能正常工作(为什么?):
#!/bin/bash
first_filename="$1"
second_filename="$2"
pattern="$3"
while read -r line
do
if [[ $line=˜$pattern ]]; then
while read -r line2
do
echo $line2
done < $second_filename
fi
echo $line
done < $first_filename