Searching for a particular string and modifying text within block of data

Hi Forum.

Is there a quick way to do the following search/replace within a block of data? I tried to google the solution but didn't really know what to look for.

I have the following text file (I want to search for a particular string "s_m_f_acct_txn_daily_a1" and replace the "$$startdate=to_char(sysdate-10,'j')" to "$$startdate=to_char(sysdate-10000,'j')" within that data block only (Appending 3 zeroes at end).

Everything else should remain as is.

Process should ask for a particular string to search for.

Original Text:
[s_m_f_acct_txn]
$PMSessionLogFile=$PMRootDir/Logs/AUTO.S_M_F_ACCT_TXN.LOG
$DBConnection_EDW=SAS2EDW
$$startdate=to_char(sysdate-10,'j')
$$enddate=to_char(sysdate, 'j')
 
 
[s_m_f_acct_txn_FULL_LOAD]
$PMSessionLogFile=$PMRootDir/Logs/AUTO.S_M_F_ACCT_TXN_FULL_LOA.LOG
$DBConnection_EDW=SAS2EDW
 
[s_m_f_acct_txn_daily_a1]
$PMSessionLogFile=$PMRootDir/Logs/SAS_FACT1/WF_FACT1_F.LOG
$DBConnection_EDW=SAS2EDW
$$startdate=to_char(sysdate-10,'j')
$$enddate=to_char(sysdate, 'j')
 
[s_m_f_asp_setup]
$PMSessionLogFile=$PMRootDir/Logs/SAS_FACT1/WF_FACT1_F.S_M_F_A.LOG
$DBConnection_EDW=SAS2EDW
$$startdate=to_char(sysdate-10,'j')

Modified Text:
[s_m_f_acct_txn]
$PMSessionLogFile=$PMRootDir/Logs/AUTO.S_M_F_ACCT_TXN.LOG
$DBConnection_EDW=SAS2EDW
$$startdate=to_char(sysdate-10,'j')
$$enddate=to_char(sysdate, 'j')
 
 
[s_m_f_acct_txn_FULL_LOAD]
$PMSessionLogFile=$PMRootDir/Logs/AUTO.S_M_F_ACCT_TXN_FULL_LOA.LOG
$DBConnection_EDW=SAS2EDW
 
[s_m_f_acct_txn_daily_a1]
$PMSessionLogFile=$PMRootDir/Logs/SAS_FACT1/WF_FACT1_F.LOG
$DBConnection_EDW=SAS2EDW
$$startdate=to_char(sysdate-10000,'j')
$$enddate=to_char(sysdate, 'j')
 
[s_m_f_asp_setup]
$PMSessionLogFile=$PMRootDir/Logs/SAS_FACT1/WF_FACT1_F.S_M_F_A.LOG
$DBConnection_EDW=SAS2EDW
$$startdate=to_char(sysdate-10,'j')

Thank you.

Is sysdate always on third line from search string? Then try this

sed "/s_m_f_acct_txn_daily_a1/{n;n;n;s/sysdate-10,/sysdate-10000,/;}" file

how about this,

 awk '{if(/s_m_f_acct_txn_daily_a1/){print;x=1}else if (x==1 && $0 ~/sysdate-/){split($0,a,",");print a[1]"000"a[2];x=0} else {print}}' inputfile
awk -vRS="\\[" -vFS="\n" '($0~/daily_a1/){i=NR}(NR==i){sub("0,","0000,",$0)}{printf((NR!=1)?RS:"")$0}' inputfile
sed '/s_m_f_acct_txn_daily_a1/,/^[ \t]*$/{/startdate/s/\(sysdate-10\),/\1000,/;}' infile
awk '/s_m_f_acct_txn_daily_a1/{s="startdate=to_char{sysdate-10";sub(s",",s"000")}1' RS= infile

Thanks guys for all your quick responses.

Sorry I did not include all possible data elements in my first example.

Another possible case scenario of data can be:

[s_m_f_mtg_res_key_meas_monthly]
$PMSessionLogFile=$PMRootDir/Logs/SAS_FACT1/WF_SAS_FACT1.LOG
$DBConnection_EDW=SAS2EDW
$DBConnection_Lkp=EDW_STG
$$startdate=to_char(TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-3)))+1,'j')
$$enddate=to_char(sysdate, 'j')

As you can see, the text that I need to replace is not always on the 3rd line and not always "sysdate-" but still want the entry to be modified to "...ADD_MONTHS(SYSDATE,-3000))..." in this example.

First search the string and within that block of data, replace -# (Where # represents 1 or more numbers) with -#000 (Add 3 more zeroes to existing text).

Also, can the code be modified so that you are prompt for the string to search?

Thank you.