Reputation: 775
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. I've tried this but it's not working:
sed "s/(^[a-z]+| [a-z]+)/house (^[a-z]+| [a-z]+)/g" textfile.
Upvotes: 3
Views: 1421
Reputation: 98078
POSIX friendly version:
sed -e 's/\([^[:alpha:]]\)\([a-z][[:alpha:]]*\)/\1house \2/g'
-e 's/^\([a-z]\)/house \1/' input
Upvotes: 1
Reputation: 195199
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
Upvotes: 3