我有两个文件。
test.log中
sadfsdfdasfasdf
2015-07-07 11:23:33,006 DEBUG : Invoking handleMessage on interceptor org.apache.cxf.interceptor.LoggingInInterceptor@2798240a
name="Demo SG, St. Gallen/*"
domicile="Ottikon"
domicile="Zürich"
domicile="Uster"
name="Luca Gubler"
2015-07-07 15:00:33,008 DEBUG : Invoking handleMessage on interceptor org.apache.cxf.interceptor.
asdfasdfasdfdsgdg
adgasdasdgsdgasdsdg
2015-07-07 16:00:33,008 DEBUG : Invoking handleMessage on interceptor and replace.txt
和replace.txt
2015-07-07 11:23:33,006 DEBUG : Invoking handleMessage on interceptor org.apache.cxf.interceptor.LoggingInInterceptor@2798240a
name="name1"
domicile="domicile1"
domicile="domicile2"
domicile="domicile3"
name="name2"
2015-07-07 15:00:33,008 DEBUG : Invoking handleMessage on interceptor org.apache.cxf.interceptor.
所以我的问题是:如何在test.log文件中合并我的replace.txt文件,以便它只替换replace.txt文件中两个时间戳之间的部分?我正在使用bash。
由于
答案 0 :(得分:2)
2种方式:
击:
mapfile -t markers < <(sed -n '1p; $p' replace.txt)
print=true
while IFS= read -r line; do
if [[ $line == "${markers[0]}" ]]; then
print=false
cat replace.txt
fi
$print && echo "$line"
[[ $line == "${markers[1]}" ]] && print=true
done < test.log
GNU awk
gawk '
NR==1 {start = $0; next}
NR==FNR {rep[++n] = $0; next}
ENDFILE {stop = $0}
$0 == start {
print;
while ($0 != stop) getline
for (i=1; i<n; i++) print rep[i]
}
{print}
' replace.txt test.log
答案 1 :(得分:1)
我在另一个堆栈溢出帖子中找到了我的脚本的解决方案
Type[]
感谢您的帮助