I am trying to read in a log file and create a new file with only the entries after the given date and time. For example I am looking for only after the time 07:00:00.000 in the below log:
2015-01-16 00:00:00.001 DATA
2015-01-16 07:05:00.121 DATA
2015-01-16 07:10:15:543 DATA
Would go to:
2015-01-16 07:05:00.121 DATA
2015-01-16 07:10:15:543 DATA
I can already get this to work with:
sed -n '/^2015-01-16 07/,$p' oglog.log > newlog.log
But when I try to add the date via a variable:
date=$(date -d -1hour +'%Y-%m-%d %H')
I cannot get it to work. I know you need to get the shell to expand variable via either double or single quotes (https://askubuntu.com/questions/76808/how-to-use-variables-in-sed-command), but with either of these methods it causes problems with $p in the replacement part of the sed command. How can I get the shell the expand one variable but not the other and use a command similar to below?
sed -n '/^$date/,$p' oglog.log > newlog.log
result=$(sed -n "/^$testDate/,$p" logtest.log > newlogtest.log)returns:sed: -e expression #1, char 20: unexpected ','andresult=$(sed -n '/^"$testDate"/,$p' logtest.log > newlogtest.log)returns an empty file.awkwhich can do>=comparisons