0

I am trying to write a bash script to get the logs from a certain timeframe by reading the log file

I am trying to use the following sed command

sed -n '/2019-12-09 03:47:26/,/2019-12-09 03:48:26/p' mqerror.log.20191209

It works fine as above, and able to retrieve the logs during that timeframe, but when i try with command substitution inside sed, itseems not working. kindly help

sed -n '/`date +'%Y-%m-%d'` 03:47:26/,/`date +'%Y-%m-%d'` 03:48:26/p' mqerror.log.`date +'%Y%m%d'`
Jon
  • 3,283
  • 2
  • 13
  • 22
  • 1
    Does this answer your question? [sed substitution with bash variables](https://stackoverflow.com/questions/7680504/sed-substitution-with-bash-variables) – Sundeep Dec 09 '19 at 08:14
  • also, use `$()` instead of backticks, see https://mywiki.wooledge.org/BashFAQ/082 – Sundeep Dec 09 '19 at 08:15
  • Does this answer your question? [refresh the command inside sed](https://stackoverflow.com/questions/57427767/refresh-the-command-inside-sed) – Jon Dec 09 '19 at 15:28

1 Answers1

0

After putting in double quotes as below. It is working as expected

sed -n "/date +'%Y-%m-%d' 0$PREV_HOUR::/,/date +'%Y-%m-%d' 0$CURR_HOUR::/p" mqerror.log.date +'%Y%m%d'