Example:
I have done my job well. i donett need any advice.
I have done my job well. I donett donett need any advice.
这是我尝试过的代码:
$ cat * | sed -E 's/\w*+done\w+*/& &/g'| grep 'done'
但是此代码也算作最终结果。 我需要使用sed来实现。
答案 0 :(得分:0)
使用awk
可以轻松完成此操作,以防万一。
awk '{for(i=1;i<=NF;i++){if($i !~ /^done$/ && $i ~ /done/){$i=$i OFS $i}}} 1' Input_file
输出如下。
I have done my job well. I donett donett need any advice.
答案 1 :(得分:0)
或您要求的sed解决方案:
echo 'I have done my job well. i donett need any advice.' | sed -r 's/(\Wdone\w+|\w+done\w+|\w+done\W)/\1 \1/g; s/ / /g'
I have done my job well. i donett donett need any advice.
答案 2 :(得分:0)
我建议使用两个表达式并将它们与|
$ cat * | sed -E 's/\w+done\w*|\w*done\w+/& &/g'
I have done my job well. I donett donett need any advice.