【发布时间】:2019-12-04 08:20:48
【问题描述】:
我有一个文件,内容如下:
[idx1]
path1 = $test/idx1/test
path2 = $test/idx1/test
path3 = $test/idx1/test
[idx2]
path1 = $test/idx2/test
path2 = $test/idx2/test
path3 = $test/idx2/test
有没有办法在分隔符之间匹配 idx1、idx2 等所有字符串,并在每次匹配后附加一个字符串。
[idx1_string]
path1 = $test/idx1_string/test
path2 = $test/idx1_string/test
path3 = $test/idx1_string/test
[idx2]
path1 = $test/idx2_string/test
path2 = $test/idx2_string/test
path3 = $test/idx2_string/test
【问题讨论】:
-
也许
echo "path2 = $test/idx2/test" | awk -F/ '{$2=$2"_string"}1'会给你一个想法。祝你好运。 -
当你在
[idx1]之后有_string(第二段)时,为什么不在_string之后呢?
标签: bash shell awk sed scripting