Results 1 to 3 of 3
What I am trying to accomplish is a way to read only the lines that have been added to the file mylog0 since the last time the script looped (5 ...
- 01-20-2011 #1Just Joined!
- Join Date
- Oct 2005
- Posts
- 12
help debugging shell script with a variable expansion
What I am trying to accomplish is a way to read only the lines that have been added to the file mylog0 since the last time the script looped (5 seconds). I am open to new suggestions too, I have been stuck on this little script for a few hours already. Thanks...
the error happens on the sed command. The same command seems to work from the command line with numbers instead of variables. This is the output of sh -xCode:#!/bin/bash i=0 firstline=0 #program loop running () { date +'%F %H:%M:%S - what i saw in the last 5 seconds:' lastline=$(wc -l "$filename"0 | awk '{print $1}') sed -n "'$firstline,${lastline}p' ${filename}0" firstline=$lastline echo ----- sleep 5 running } read filename < /var/tmp/mylogfilename running
Code:+ running + date +%F %H:%M:%S - what i saw in the last 5 seconds: 2011-01-20 09:18:59 - what i saw in the last 5 seconds: + wc -l mylog0 + awk {print $1} + lastline=16 + sed -n '4,16p' sed: -e expression #1, char 1: unknown command: `'' + firstline=16 + echo ----- ----- + sleep 5
- 01-20-2011 #2Just Joined!
- Join Date
- Oct 2005
- Posts
- 12
eval sed -n "'${firstline},${lastline}p'" ${filename}0
needed the eval in front of the sed i guess, seems to work
- 01-22-2011 #3Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
What you need to do is lose the double quotes on the sed line, and replace the single quotes with double quotes.
Then learn how to use quotes.


Reply With Quote