1

I have a list of files with strings like {{abc-exfs-value}}. The sub string abc differs in each of the file. For example, a regex search (java) like: \{\{*-exfs-value\}\} will return all the strings that is of concern here. How to proceed on replacing all those strings that match the regex pattern in files in linux?

I am able to get the list of files using grep -R '\-exfs\-value' .. Using sed how to replace the strings?

7
  • What do you want to replace it with? Commented Sep 10, 2014 at 17:28
  • 1
    Have you tried anything already? This sounds like a simple sed 's/pattern/replacement/'. Commented Sep 10, 2014 at 17:32
  • {{abc-exfs-value}} with {{xyz-exfs-value}}. The many variations in abc with a 'xyz'. Commented Sep 10, 2014 at 17:32
  • The "abc" part, is that only letters? Are there numbers? Are there other symbols? Commented Sep 10, 2014 at 17:36
  • Use sed 's/\({{\)[^-]*\(-.*}}\)/\1xyz\2/' Commented Sep 10, 2014 at 17:38

1 Answer 1

1

I would think this is what's needed:

sed -i.bak 's/\({{\)[[:alnum:]]\+\(-exfs-value}}\)/\1xyz\2/g' file1 file2 ...
Sign up to request clarification or add additional context in comments.

3 Comments

sed must be old school, forces you to escape metachars?
@sln sed by default uses BRE hence the need for escaping meta-characters. Depending on the version of your sed you can enable ERE by doing -E (BSD) or -r (GNU). There is another variant of sed called super-sed or ssed which supports PCRE if you enable -R option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.