Skip to main content
added 313 characters in body
Source Link
conanDrum
  • 465
  • 1
  • 5
  • 17

I use the following to successfully find my ANCHOR (regex pattern) and replace it with my param-value inside a file (filepath).

sed -i $"/$ANCHOR/i \\$PARAMVALSEDINS" "$FILEPATH" 

What I need is for when my ANCHOR is '' (empty) to instead match my EOF and do the replacement there.

So I imagine doing something like this:

if ANCHOR='' then ANCHOR='$EOF' so that SED successfully finds the EOF and proceeds with the replacement.

Can this be done? Couldn't find anything specific except for this:

sed -i -e "\$aPARAMVALSEDINS" "$FILEPATH" 

However, this does not involve the ANCHOR variable and I will implement it if my question is not possible to be answered.

PS. Of course it could be possible to use another method altogether. Maybe there is a way to do this with another command that DOES facilitate regex matching AND EOF matching within the regex area? e.g. another -i $"/$ANCHOR/i \$PARAMVALSEDINS" "$FILEPATH" where if $ANCHOR can be a match for EOF

Thanks

I use the following to successfully find my ANCHOR (regex pattern) and replace it with my param-value inside a file (filepath).

sed -i $"/$ANCHOR/i \\$PARAMVALSEDINS" "$FILEPATH" 

What I need is for when my ANCHOR is '' (empty) to instead match my EOF and do the replacement there.

So I imagine doing something like this:

if ANCHOR='' then ANCHOR='$EOF' so that SED successfully finds the EOF and proceeds with the replacement.

Can this be done? Couldn't find anything specific except for this:

sed -i -e "\$aPARAMVALSEDINS" "$FILEPATH" 

However, this does not involve the ANCHOR variable and I will implement it if my question is not possible to be answered.

I use the following to successfully find my ANCHOR (regex pattern) and replace it with my param-value inside a file (filepath).

sed -i $"/$ANCHOR/i \\$PARAMVALSEDINS" "$FILEPATH" 

What I need is for when my ANCHOR is '' (empty) to instead match my EOF and do the replacement there.

So I imagine doing something like this:

if ANCHOR='' then ANCHOR='$EOF' so that SED successfully finds the EOF and proceeds with the replacement.

Can this be done? Couldn't find anything specific except for this:

sed -i -e "\$aPARAMVALSEDINS" "$FILEPATH" 

However, this does not involve the ANCHOR variable and I will implement it if my question is not possible to be answered.

PS. Of course it could be possible to use another method altogether. Maybe there is a way to do this with another command that DOES facilitate regex matching AND EOF matching within the regex area? e.g. another -i $"/$ANCHOR/i \$PARAMVALSEDINS" "$FILEPATH" where if $ANCHOR can be a match for EOF

Thanks

added 30 characters in body
Source Link
conanDrum
  • 465
  • 1
  • 5
  • 17

I use the following to successfully find my ANCHOR (regex pattern) and replace it with my param-value inside a filepathfile (filepath).

sed -i $"/$ANCHOR/i \\$PARAMVALSEDINS" "$FILEPATH" 

What I need is for when my ANCHOR is '' (empty) to instead match my EOF and do the replacement there.

So I imagine doing something like this: if ANCHOR='' then ANCHOR='$EOF' so that SED successfully finds the EOF and proceeds with the replacement.

if ANCHOR='' then ANCHOR='$EOF' so that SED successfully finds the EOF and proceeds with the replacement.

Can this be done? Couldn't find anything specific except for this:

sed -i -e "\$aPARAMVALSEDINS" "$FILEPATH" 

However, this does not involve the ANCHOR variable and I will implement it if my question is not possible to be answered.

I use the following to successfully find my ANCHOR and replace it with my param-value inside a filepath.

sed -i $"/$ANCHOR/i \\$PARAMVALSEDINS" "$FILEPATH" 

What I need is for when my ANCHOR is '' (empty) to instead match my EOF and do the replacement there.

So I imagine doing something like this: if ANCHOR='' then ANCHOR='$EOF' so that SED successfully finds the EOF and proceeds with the replacement.

Can this be done? Couldn't find anything specific except for this:

sed -i -e "\$aPARAMVALSEDINS" "$FILEPATH" 

However, this does not involve the ANCHOR variable and I will implement it if my question is not possible to be answered.

I use the following to successfully find my ANCHOR (regex pattern) and replace it with my param-value inside a file (filepath).

sed -i $"/$ANCHOR/i \\$PARAMVALSEDINS" "$FILEPATH" 

What I need is for when my ANCHOR is '' (empty) to instead match my EOF and do the replacement there.

So I imagine doing something like this:

if ANCHOR='' then ANCHOR='$EOF' so that SED successfully finds the EOF and proceeds with the replacement.

Can this be done? Couldn't find anything specific except for this:

sed -i -e "\$aPARAMVALSEDINS" "$FILEPATH" 

However, this does not involve the ANCHOR variable and I will implement it if my question is not possible to be answered.

edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 266
added 8 characters in body
Source Link
conanDrum
  • 465
  • 1
  • 5
  • 17
Loading
Source Link
conanDrum
  • 465
  • 1
  • 5
  • 17
Loading