sed -i 's/WORD1.*WORD3/WORD1 foo WORD3/g' file.txt
or
sed -i 's/(WORD1).*(WORD3)/\1 foo \2/g' file.txt
You might need to escape round brackets, depends on your sed variant.
More Related Contents:
- RE error: illegal byte sequence on Mac OS X
- How to extract text from a string using sed?
- Why is sed not recognizing \t as a tab?
- Insert linefeed in sed (Mac OS X)
- Replace a word with multiple lines using sed?
- How to change date format in sed?
- How can I output only captured groups with sed?
- How do I use regular expressions in bash scripts?
- Check if a string matches a regex in Bash script
- Insert contents of a file after specific pattern match
- Using sed to delete all lines between two matching patterns
- Using the star sign in grep
- Why doesn’t `\d` work in regular expressions in sed? [duplicate]
- How to extract string following a pattern with grep, regex or perl [duplicate]
- How do you extract IP addresses from files using a regex in a linux shell?
- Bash, grep between two lines with specified string
- Search and replace in bash using regular expressions
- Fully qualified domain name validation
- sed join lines together
- How do I use a regex in a shell script?
- Remove duplicates from text file based on second text file
- How to match a pattern given in a variable in awk?
- Sed to extract text between two strings
- Recursively change file extensions in Bash
- How do I use a new-line replacement in a BSD sed?
- Why does BASH_REMATCH not work for a quoted regular expression?
- How to execute a Bash command only if a Docker container with a given name does not exist?
- Bash – Regex for HTML contents
- How to extract domain name from url?
- Whats the difference between sed -E and sed -e