I have 2 files and would like to replace the 1st matching block of text from file1 (matching criteria start indicator as <<EOF and End of block criteria is EOF) with sed from another file2 data.
Example:
file1
resource "policy" "temp1" {
policy = << EOF
{
policy1-data
}
EOF
}
resource "policy" "temp2" {
policy = << EOF
{
policy2-data
}
EOF
}
file2
{
modified-policy-data
}
output file
resource "policy" "temp1" {
policy = << EOF
{
modified-policy-data
}
EOF
}
resource "policy" "temp2" {
policy = << EOF
{
policy2-data
}
EOF
}
I tried below sed command but that replaces all occurrences of matching criteria in file1 from file2 data where I would like to replace only first matching block occurrence and rest keep same as is from file1
lead='<<EOF'
tail='EOF'
sed -nie '/'"$lead"'/ { p r file2 :a n /'"$tail"'/ { p b } ba }p' file1