sed command issue in script

Hi,

I am using sed command to extract data from my log file for a certain time interval. From and To "time" are my input arguments.
Now if i use the sed command on command line. I get the desired results and If i use it in script.It fails.
sed command as command line:

sed -n '/04-Mar-2015 12:51:08/,/04-Mar-2015 12:51:52/p' test.log | grep 'fail' >new.log

This one works fine.

In script , I am using

sed -n '/$FromTime/,/$ToTime/p' $logFile  > new_log.log

and as I input time while running script, I get below error

user@host> sh log.sh test.log 04-Mar-2015 12:51:08 04-Mar-2015 12:51:52
sed: 0602-419 Cannot find or open file 04-Mar-2015.

Can anyone help me what am i missing in script??I am new to scripting.Any help would be highly appreciated.

Use double quotes instead of single quotes to expand the shell variables:

sed -n "/$FromTime/,/$ToTime/p" $logFile  > new_log.log
1 Like

No its not working . I am getting the same error

---------- Post updated at 08:42 AM ---------- Previous update was at 08:24 AM ----------

I tested that wrong.. sorry.. I am still getting the same error

Confused with your update. Is it working or not?
If not, what error are you getting?

No, its not working.. I tested wrong. I get the below error

sed: 0602-419 Cannot find or open file 04-Mar-2015.

More context, please! How do you translate the positional parameters $2 - $5 into Fromtime and Totime ?

Well, read the error again and guess. Its unable to access the file. Make sure its available. more precisely in the current directory.