Ok I am locked in a situation where I am trying to insert a line based on a search string . I am familiar doing this w AWK and SED using a single work or something uncomplicated.
How I’d like to insert a string that has Single Quotes and Brackets
e.g.
this will work
awk '/('Backup/ {print "NEWLINE" } {print}' filename.sh
and so will this
sed -e '/\(\'backup/i\
newline ' filename.sh
Instead of newline work- I want this ” (‘Drop the no good white.cap ;’ ) , “
everything enclosed within the ” and ”
What you’re trying to do has nothing to do with
awkorsed. For example, see:The first
'character closes the opening'shell string literal. The shell literal does not support a backslash escape for this. The sequence'\''does the trick: it closes the single-quote literal, specifies the quote character (using an escape that is supported outside of single-quote literals) and then re-opens a new single-quote literal. You can think of it as a four-character escape sequence to get a single quote.So, your
awkcommand becomes:And your
sedcommand becomes:EDIT:
Explanation:
Loop over all files in the directory using a shell
forloop. Add a header to the files with theBEGINblock. Find the wordbackupand print a line containing the shell variablesDBandTB.... }1'at the end of theawkscript enables printing by default. It’s shorthand for{ print }. HTH.