简体   繁体   English

将带有sed的单词插入到文本文件中

[英]Insert a word with sed into a text file

I have a text file and I want to insert a word like house before every word that begins with a lower-case letter in a file, using sed. 我有一个文本文件,我想每一个以小写字母开头的文件,使用SED字之前插入喜欢的房子一个字。 I've tried this but it's not working: 我试过这个,但它不起作用:

sed "s/(^[a-z]+| [a-z]+)/house (^[a-z]+| [a-z]+)/g" textfile.

I got this line, is it ok for you? 我有这条线,你还好吗?

sed -r 's/\b[a-z]\w*\b/HOUSE &/g' file

with example: 用例子:

kent$ echo "yes No yES NO y_e_s _no"|sed -r 's/\b[a-z]\w*\b/HOUSE &/g'
HOUSE yes No HOUSE yES NO HOUSE y_e_s _no

POSIX friendly version: POSIX友好版:

sed -e 's/\([^[:alpha:]]\)\([a-z][[:alpha:]]*\)/\1house \2/g' 
    -e 's/^\([a-z]\)/house \1/' input

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM