Bash点的选择性替换

Bash点的选择性替换,bash,sed,Bash,Sed,我有以下格式的文件名: My.File.d01.h01.txt My.New.File.d01.h02.txt My.Another.File.d01.h03.txt My.Yet.Another.File.d01.h04.txt File.d01.h05.txt 我想删除“d01.h01”、“d01.h02”、“d01.h03”等之间的点 我想我需要使用某种形式的sed,但我需要保留dXX和hYY值 期望输出: My.File.d01h01.txt My.New.File.d01h02.tx

我有以下格式的文件名:

My.File.d01.h01.txt
My.New.File.d01.h02.txt
My.Another.File.d01.h03.txt
My.Yet.Another.File.d01.h04.txt
File.d01.h05.txt
我想删除“d01.h01”、“d01.h02”、“d01.h03”等之间的点

我想我需要使用某种形式的sed,但我需要保留dXX和hYY值

期望输出:

My.File.d01h01.txt
My.New.File.d01h02.txt
My.Another.File.d01h03.txt
My.Yet.Another.File.d01h04.txt
File.d01h05.txt

有什么帮助吗?

这里有一个
awk
可能会有帮助:

awk -F. '{for (i=1;i<NF;i++) {if ($i~/d[0-9][0-9]/) f=1;printf "%s"(f?"":FS),$i}print FS $NF;f=0}' file
My.File.d01h01.txt
My.New.File.d01h02.txt
My.Another.File.d01h03.txt
My.Yet.Another.File.d01h04.txt
File.d01h05.txt

awk-F.{for(i=1;i使用反向引用:

sed -r 's/(\bd[0-9]+)\.(h[0-9]+)/\1\2/' inputfile
对于您的示例输入,它将产生:

My.File.d01h01.txt
My.New.File.d01h02.txt
My.Another.File.d01h03.txt
My.Yet.Another.File.d01h04.txt
File.d01h05.txt
检查
d
之前的单词边界,或确保其前面有

sed -r 's/(\.d[0-9]+)\.(h[0-9]+)/\1\2/' inputfile

太棒了!非常感谢您的快速回复。