shell - Replace content in a file or line matching a regular expression using SED -


how replace line / part of line in file using sed command?

search_text_1_server=value.env_1.path_to_file search_text_2_server=value.env_1.path_to_file search_text_3_server=value.env_1.path_to_file some_other_key=value.env_1.another_path 

now want sed command find lines match regular expression search_text_{any}_server , replace env_1 env_2

found regular expression find required lines.

^search_text_[a-z_]\*_server.*$

now how add sed syntax replace

ps : not expert in shell

your regex close. can use:

sed -e 's/^(search_text_[a-z_]*_server=.*)env_1\./\1env_2\./' file  search_text_1_server=value.env_2.path_to_file search_text_2_server=value.env_2.path_to_file search_text_3_server=value.env_2.path_to_file some_other_key=value.env_1.another_path 

Comments