It is currently Sat, 04 Dec 2021 18:23:13 GMT



 
Author Message
 using sed to delete unwanted data
Hi,
I have a log file that I would like to check for new errors on a regular
basis. To prevent reviewing already viewed errors I want to right a marker
to the log file after viewing it so that everytime I execute this script it
will copy the log file to a temp file and then using sed it will delete
everything up until the last marker (there will obviously be many markers
written to this log file).
What I have thus far is this , but it doesn't seem to work properly - I just
keep getting a resultant file which is empty.
Any help would be greatly appreciated.

cat << EOF > sedfile
1,"STOP_MARKER",d            # this is to delete everything up to the marker
(STOP_MARKER) written to the log #
EOF
#
while [ `grep -c "STOP_MARKER" $logfile` -ne 0]       # run through all the
markers written to the log file #
do
    sed -f $sedfile $logfile > $templogfile
    cp $templogfile $logfile
done
#

Thanks.



 Sun, 20 Jul 2003 04:17:05 GMT   
 using sed to delete unwanted data

Since you're using grep to find all the markers in the file, why don't you
use grep -n to get their line numbers, grab the line-number of the last
marker, and then use tail to skip over that many lines.  Or better yet, do
it all in one awk:

marker_line=`awk 'BEGIN {marker_line=0}
                  /STOP_MARKER/ {marker_line=NR}
                  END {print marker_line}' $logfile`
tail +$marker_line $logfile > $templogfile

--
Barry Margolin, bar...@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



 Sun, 20 Jul 2003 05:43:31 GMT   
 using sed to delete unwanted data

wHY not use tail to help out ?;

tail -r $logfile|sed /STOP_MARKER/q|tail -r >$templogfile
mv $templogfile $logfile

Bye,

L



 Sun, 20 Jul 2003 23:12:20 GMT   
 
   [ 3 post ] 

Similar Threads

1. Using awk/sed to delete a line.

2. delete pattern using sed

3. Using ed/sed to delete entries from a flat file

4. Using sed to delete blank spaces

5. Using sed to delete non-numeric lines

6. Using sed to delete pattern from lines

7. deleting records in a file using AWK, SED, or kshell


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software