shell - sed:保留包含 block 模式的每个单词的最后一个 block

标签 shell sed

愿意只保留最后一个包含点的单词 block (仍然保留不包含模式的单词):

sed 似乎只匹配最后一个单词:

$ echo "Here this.is.a.start is a very.nice.String  that.is.the.end yes " | sed 's/.*[ ]\([^ ]*\.\)\([^ ]*\)[ ].*/\2/g'
end

$ echo "Here this.is.a.start is a very.nice.String  that.is.the.end yes " | sed 's/.*[ ]\([^ ]*\.\)\([^ ]*\)[ ].*/\1/g'
that.is.the.

我应该怎样做才能得到这个结果? :

echo "Here this.is.a.start is a very.nice.String  that.is.the.end yes " | sed s\\\g
Here start is a String  end yes

最佳答案

用\w 表示一个单词:

echo "Here this.is.a.start is a very.nice.String  that.is.the.end yes " |
 sed -E 's/\w*\.//g'

关于shell - sed:保留包含 block 模式的每个单词的最后一个 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64281386/

相关文章:

linux - grep 匹配模式的文件名并 move 到所需的文件夹

linux - 返回同一文件中最后一个匹配的 String2 之后与文件中的 String1 匹配的所有行

bash - 在替换命令 '/' 中获取错误标志以进行 sed 替换

linux - 替换括号中的单词以放入引号中

linux - 在 shell 脚本中从文件中提取特定模式

c - 逐行读取的 shell

regex - 遵循特定模式的正则表达式

sql - 在 sql 中将西欧字符集转换为土耳其语

unix - 如何在 sed 的命令中使用变量?

C#:运行 shell 命令时出现问题