Skip to main content
3 of 5
edited tags
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 266

SED regex match EOF and replace/insert

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.

conanDrum
  • 465
  • 1
  • 5
  • 17