linux - sed any whole word search and replace -
how can match any whole word in input text, replace replacestring. example. sed command match word in input text , replace each of them "xxx".
echo "bar embarrassment recommended" | sed "please fill right answer here"
i output this
xxx xxx xxx
i new linux.so there may other command can work best here in situation.any recommendation?
the definition of word in question simple. can contain alphabets a-z or a-z ,an underscore. , 2 words delimited white space.
examples
"this sample text" "this sample text" "this_ is_ a_ sample_ text_"
matchew's helpful answer contains gnu sed solution, appropriate, given question tagged linux.
in comment, you're on mac (os x), comes bsd sed, behaves differently in many respects.
the posix-compliant (and cross-platform) equivalent of matchew's command is:
echo "bar embarrassment recommended." | sed 's/[[:alnum:]_]\{1,\}/xxx/g' however, note this match words on any boundary, not whitespace; i.e., run of word characters adjoined any non-word character match, abc-de turn xxx-xxx, instance.
Comments
Post a Comment