I want to append below find command in a file under a line matching a string.
command:
Quote:
find /path/to/dir -type f \( -name '*.gz' -o -name '*.log' \) -mtime + ${days} -exec rm -fr {} \;
|
File:
I am taking a command in variable and then using sed to add command via variable under a line below match.
Quote:
$ COMM=`echo "find /path/to/dir -type f \( -name '*.gz' -o -name '*.log' \) -mtime + ${days} -exec rm -fr {} \;"`
$ sed -i "/for id abc/a ${COMM}" disk.sh
|
However in output \ dissappears.
Quote:
$ cat disk.sh
for id abc
find /path/to/dir -type f ( -name '*.gz' -o -name '*.log' ) -mtime + ${days} -exec rm -fr {} ;
|
But variable seem to have captured the whole command perfectly.
Quote:
$ echo ${COMM}
find /path/to/dir -type f \( -name '*.gz' -o -name '*.log' \) -mtime + ${days} -exec rm -fr {} \;
|