Question

There is a possibility to search using grep in TextWrangler

I want to find and replace the following word: bauvol, but not bauvolumen. I tried typing ^bauvol$ into the search field but that didn't do the trick, it didn't find anything, although the word is clearly there.

I think it's because, in grep, the ^and $signify start and end of line, not a word?!

Was it helpful?

Solution

You want to use \b as word boundaries, as @gromi08 said:

\bbauvol\b

If you want to copy any portion of this word (so you can replace it, modify it, change the case, etc.) it is usually best to wrap it in ( and ) braces so you can reference them in the Replace box:

Find:
  (\bbauvol\b)

Replace:
  <some_tag>\1</some_tag>

Did you have anything specific you were trying to do with the result once you found it (cut it, duplicate it, etc.)?

OTHER TIPS

Use the -w option of grep (see grep man-page. This option searches for the expression as a word.

Therefore the command will be:

cat file.txt | grep -w bauvol

And yes, ^ and $ are for start and end of line.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top