3

I want to use sed command as below:

$ sed -n '/MONTH_TODAY DATE_YEST/,/MONTH_TODAY DATE_TODAY/p' \
   /home/crmiib/TESTUSERLOG/XYZ/user.log

I can print logs using:

$ sed -n '/Jul 27/,/Jul 28/p' /home/crmiib/TESTUSERLOG/XYZ/user.log

But I want to view logs using variables instead of hard coded dates?

1 Answer 1

4

Use double quotes so the shell evaluates the variables before sed runs:

DATE_YEST="Jul 27"
DATE_TODAY="Jul 28"
sed -n "/$DATE_YEST/,/$DATE_TODAY/p" /home/crmiib/TESTUSERLOG/XYZ/user.log
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.