Search code examples
bashsedlines

Adding Text After Specific Line of File in Bash Script w/o SED


I am trying to append a line under a specific line, lets say [BELOW HERE] and without using SED. What is the best alternative way to do this?

I've tried to use SED but this was not supported for the machine where the script was made for.

sed --in-place "/^\[BELOW HERE\]/a BLabla=Database toolSomething" file 

/a = append


Solution

  • You don't need awk, sed or any other third party built-ins for this trivial task. You can use the ed editor available from the UNIX days available in all major distributions these days,

     printf '%s\n' 'g/[BELOW HERE]/s/\r/BLabla=Database toolSomething
    /g' w q | ed -s file