I’m trying to delete a part of a file using sed in Linux (Ubuntu). Specifically, I want to delete the first lines of a log file until the first occurrence of the current system date (using the pattern ’10 Jan 13′).
So, I store the date in a variable
root@server:/# VAR_DATE=`date -R | cut -c6-11`
And after that, I use sed
root@server:/# cat log_file.txt | sed -n -e '/$VAR_DATE/,$p'
But it doesn’t work. I’ve tried a lot of combinations with the same result:
root@server:/# cat log_file.txt | sed -n -e '/"$VAR_DATE"/,$p'
root@server:/# cat log_file.txt | sed -n -e '/"${VAR_DATE}"/,$p'
root@server:/# cat log_file.txt | sed -n -e "/$VAR_DATE/,$p"
What I’m doing wrong?
Use double quotes so the variable
$vardategets expanded by the shell and escape the last$so it’s not expanded by the shellsed -n "/$vardate/,\$p" file: