如果一个句子与特定的单词开始,如何改变一个词的那句话,如果确实存在吗? [英] If a sentence starts with a specific word, how to change a word in that sentence if it does exist?
本文介绍了如果一个句子与特定的单词开始,如何改变一个词的那句话,如果确实存在吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,基本上在搜索.txt文件的行,如果它如这字开头,如何在这句话换一个字的目标,如果确实存在吗?开放使用bash,Perl或AWK这样做。
解决方案
的perl -pi -eS / ^这个\\ B /这/MYFILE
或者,如果你想行内改变的不同的的字,
的perl -pi -eS / \\ btargeted \\ B /交换/ IF / ^这个\\ B /MYFILE
So, basically searching the lines in .txt file and if it starts with a word such as "This", how to swap a targeted word in that sentence if it does exist? Open to doing it with bash, perl or awk.
解决方案
perl -pi -e "s/^This\b/That/" myfile
or, if you want to change a different word within the line,
perl -pi -e "s/\btargeted\b/swap/ if /^This\b/" myfile
这篇关于如果一个句子与特定的单词开始,如何改变一个词的那句话,如果确实存在吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文