Issue
I am looking to update one config file using bash.
Config file is having multiple section like
[SECTION1]
action.email.useNSSubject = 1
dispatch.earliest_time = 1578927600
dispatch.latest_time = 1579016736
search = | inputlookup KPI_MASTER_LIST.csv | search TYPE="MTE_GENERIC" \
| table ALERT Order\
| map maxsearches=21 search="| savedsearch "$$ALERT$$" host_token=$host_token$ SERVICE_EARLIEST_TIME=$SERVICE_EARLIEST_TIME$ time_token.earliest=$time_token.earliest$ time_token.latest=$time_token.latest$ | appendcols [ | makeresults | eval Order="$$Order$$" | fillnull count ] | table ALERT count Order "\
| sort Order \
[SECTION2]
action.email.useNSSubject = 1
alert.track = 0
dispatch.earliest_time = 153437300
dispatch.latest_time = 1549013433
display.general.timeRangePicker.show = 0
search = | inputlookup KPI_MASTER_LIST.csv | search TYPE="MTE_GENERIC" \
| table ALERT Order\
| map maxsearches=21 search="| savedsearch "$$ALERT$$" host_token=$host_token$ SERVICE_EARLIEST_TIME=$SERVICE_EARLIEST_TIME$ time_token.earliest=$time_token.earliest$ time_token.latest=$time_token.latest$ | appendcols [ | makeresults | eval Order="$$Order$$" | fillnull count ] | table ALERT count Order "\
| sort Order \
I am looking to update value of "dispatch.earliest_time" and "dispatch.latest_time" in specific section only(not all occurrence of this file)
Solution
You could use an address range specifying your delimiter
sed '/\[SECTION_NAME\]/,/^\[/ s/dispatch.earliest_time/new_value_here/'
You can find thorough documentation about sed here
Answered By - Dexirian Answer Checked By - Willingham (WPSolving Volunteer)