0

Identical to this question:

Find and replace text within a file using commands

However I want an answer that utilizes regular expressions specifically. So in short:

Using commandline; what command can I used to search and replace text in a commandline while utilizing regular expressions?

For example:

search file.txt "([a-z]+)" "\1 blah"
Anon
  • 12,063
  • 23
  • 70
  • 124

1 Answers1

3

Seems like you want something like this,

$ cat file
foo bar
$ sed 's/\([a-z]\+\)/\1 blah/g' file
foo blah bar blah

\([a-z]\+\) captures one or more lowercase letters. Then the matched characters are replaced by the characters which are present inside the group index 1 plus the string " blah".

Avinash Raj
  • 78,556