Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 04 Sep 1998 12:13:10 -0400
From:      Roman Katsnelson <romank@graphnet.com>
To:        Dan Nelson <dnelson@emsphone.com>
Cc:        "q's" <freebsd-questions@FreeBSD.ORG>
Subject:   Re: grep question
Message-ID:  <35F01196.BA6A7F7F@graphnet.com>
References:  <35EFEEA4.65B3315F@graphnet.com> <19980904095358.A7658@emsphone.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> --- deleterecord ---
> #!/bin/sh
> 
> file="file.txt"
> recid=$1
> # get the starting line number for the record we're interested in
> line=$(grep -n "^# --->$recid" $file) # grep -n prepends line with line num
> linenum=${line%%:*}  # remove everything after the first colon
> 
> if [ -z "$linenum" ] ; then
>         echo Record $recid not found
>         exit 1
> fi
> 
> # calculate the start and end line numbers
> start=$(( $linenum - 2 ))
> end=$(( $linenum + 13 ))
> 
> # delete the offending record
> sed -e "${start}-${end}d" < $file > $file.tmp


Thank you! 
When I test this on an actual record, though,
it returns:

sed: 1: "270-285d": invalid command code -

any ideas?

btw, what's a good book on sed and awk and sh etc.?

mucho thanks AA

roman

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?35F01196.BA6A7F7F>