data@buhub (Mark Hall) (01/25/91)
I'm having a minor problem. I want to use a shell script that I have in my .profile to do some things dealing with mail. I use checkmail and a custom script that keeps track of the number of new messages. When I log in, it tells me how many NEW messages I have by subtracting the number of lines returned from the Checkmail /usr/mail/data | wc -l by the number in the .mailchk file I create (it only contains a single number). When I display the messages in my mailbox, I'd like to remove the first "x" lines from the listing. Any suggestions? SUmmary: WHat I want to do is pass the number in the .mailchk file and delete that number of lines from the beginning of my input by using sed. Mark hall -- | Internet: data@{bucs1,buhub}.bradley.edu, al632@cleveland.freenet.edu | |-----------------------------------------------------------------------------| | F'net : 1:232/28 1:2250/9 (fname.lname@f<node>.n<net>.z<zone>.fidonet.org) | |-----------------------------------------------------------------------------| | "He sees you when you're sleeping, he knows when you're awake, but Captain, | | it makes no sense!" "But Spock, with Santa, ALL things are possible!" | | Kirk and Spock...Hallmark Greeting Cards |
]) (01/26/91)
In article <1991Jan25.070712.17725@bradley.bradley.edu> data@buhub (Mark Hall) writes: >I'm having a minor problem. I want to use a shell script that I have in my >.profile to do some things dealing with mail. I use checkmail and a custom >script that keeps track of the number of new messages. When I log in, it >tells me how many NEW messages I have by subtracting the number of lines >returned from the Checkmail /usr/mail/data | wc -l by the number in the >.mailchk file I create (it only contains a single number). >When I display the messages in my mailbox, I'd like to remove the first "x" >lines from the listing. Any suggestions? > >SUmmary: WHat I want to do is pass the number in the .mailchk file and delete >that number of lines from the beginning of my input by using sed. > >Mark hall If your .mailchk file contains *only* the integer through which you want to delete, ... : # This is the ksh version KSH=/bin/ksh CMD=/usr2/myid/bin/chkmail # # Make sure this is ksh # if [ "$RANDOM" = "$RANDOM" ] then exec $KSH $CMD $* exit 1 # exec failed! fi # Set important vars 'cause I'm too lazy to keep typing them CNTL=~/.mailchk MB=/usr/mail/$(logname) # Make the variable 'i' a decimal integer typeset -i10 i # If the control-file is empty, then we've seen nothing if [ ! -f $CNTL ] then i=0 else i=$(<$CNTL) fi # If we've seen nothing, list the whole MB if [ $i -eq 0 ] then cat $MB else sed "1,${i}d" $MB fi wc -l < $MB > $CNTL exit To convert to sh, you'l need to replace some of the short-and-sweet steps with expr and cat calls and the $(cmd) stuff with `cmd`, but the call to sed 3 lines above the exit is what you're looking for. Also, the output of wc -l, on my system at least, provides a leading space before the number. By typeset -i10 i I force that blank to be removed from the variable when i=$(<$CNTL) is done. In sh, where typeset doesn't exist, one needs to take care of the space either on the write to $CNTL or the read from it. ...Kris -- Kristopher Stephens, | (408-746-6047) | krs@uts.amdahl.com | KC6DFS Amdahl Corporation | | | [The opinions expressed above are mine, solely, and do not ] [necessarily reflect the opinions or policies of Amdahl Corp. ]
Gerhard.Moeller@arbi.informatik.uni-oldenburg.de (Gerhard Moeller) (01/26/91)
data@buhub (Mark Hall) writes: >I'm having a minor problem. I want to use a shell script that I have in my >.profile to do some things dealing with mail. I use checkmail and a custom >script that keeps track of the number of new messages. When I log in, it >tells me how many NEW messages I have by subtracting the number of lines >returned from the Checkmail /usr/mail/data | wc -l by the number in the >.mailchk file I create (it only contains a single number). >When I display the messages in my mailbox, I'd like to remove the first "x" >lines from the listing. Any suggestions? No problem: x=<whatever you like> sed '1,'$x'd' < .... > .... If you want to write onto the same lising file, use the "overwrite" from Kernighan. >SUmmary: WHat I want to do is pass the number in the .mailchk file and delete >that number of lines from the beginning of my input by using sed. So long, Gerhard. -- +---------------------------< principiis obsta! >---------------------------+ | Gerhard Moeller, Teichstrasse 12, 2900 Oldenburg (FRG) [Geb. 02/21/68] | | inhouse: faramir!gemoe uucp: ...(unido!)uniol!gmoeller | |DOMAIN: gerhard.moeller@arbi.informatik.uni-oldenburg.de | |BITNET: gmoeller%arbi.informatik.uni-oldenburg.de@DOLUNI1 (106495@DOLUNI1) | +-----------------------> the medium is the message <-----------------------+