I edited the post and I follow your advice, I splitted my work in more files.
I want to replace a text block inside a file but after a delimiter
<-FROM NEXT LINE->
code to be replaced
code to be replaced
code to be replaced
<-TO THE LINE ABOVE->
Because I collect online data, time by time the data is different, so the code that have to be replaced is different too.
This's the portion of the script:
#!/bin/bash
set -x
########## CONFIGURATIONS ##########
live_data_url='https://www.somedata.com/api/url'
live_data_list_file=~/jjjjjjjj
file_to_modify=~/kkkkkkk
########## CONFIGURATIONS ##########
########## FUNCTIONS ##########
function upgrade() {
echo "Downloading/Upgrading traker data ..."
wget -O $live_data_list_file $live_data_url
if [[ $? -ne 0 ]]; then
echo "I can't download the data, I'll use a static one"
exit 9
fi
echo "Downloading/Upgrading done."
}
########## FUNCTIONS ##########
upgrade
sed -i -ne '/STARTINGPOINT+1LINE/ {p; r $live_data_list_file' -e ':a; n; /ENDINGPOINT-1LINE/ {p; b}; ba}; p' $file_to_modify
The goal is to upgrade the block inside the $file_to_modify
section:
<-FROM NEXT LINE->
code to be replaced
code to be replaced
code to be replaced
<-TO THE LINE ABOVE->
so I searched a bit and I found a good starting point, but I don't know how to modify it. Is not a requisite the use of sed, maybe exist a better way to do this
Actually I've 2 difficulty
1. I need to start after the line that contain <-FROM NEXT LINE->
and I need to stop the line above <-TO THE LINE ABOVE->
2. The expansion of $live_data_list_file
inside the sed phase is not working, so I can't take data from file.
Do you have a better idea to do this?