shell - sed:保留包含块模式的每个单词的最后一块
问题描述
愿意只保留最后一块包含点的单词(仍然保留不包含模式的单词):
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'
推荐阅读
- python - 编码过程时脚本被杀死
- javascript - 如何将光标放在 IE 文本输入元素中的文本末尾
- google-apps-script - 需要有关 GoogleScript 上的 Onedit 功能的帮助(电子表格)
- android-layout - 如何从图像视图中心水平图像视图
- awk - awk 数组以意外的顺序打印元素
- python - 如何在 Pandas 中按列而不是按行对值进行排序?
- python - 如何在 Pyspark 中应用 groupby 和 transpose?
- linux - 在 docker 环境中的 Centos 上出现“无法设置语言环境,默认为 C”的错误(yum 安装)
- android - 区分第一次启动活动时调用的 OnResume 与按下后退按钮时调用
- angularjs - $cookies.get 显示未定义