Script and Comments
Script1
[ 1] /PAT/,$!d
Comments
  1. The 2-address specification
    /PAT/,$
    'splits' the datafile to be processed into two parts:
    • Lines BEFORE the FIRST one containing 'PAT',
      although these lines do NOT match
      /PAT/,$
      but the negation (!) will make the command 'd' performed on these lines!.
    • The other.
      Step [1] will not be performed. Since the end of script is reached, sed will print out the contents of pattern space and start a new cycle.
Raw Input
Oct 15 10:35:41 main login: DIALUP AT ttyS1 BY john
Oct 15 10:35:41 main login: LOGIN ON ttyS1 BY john
Oct 15 12:37:14 main ipop3d[26563]: connect from 10.2.1.103
Oct 15 15:44:26 main in.telnetd[27345]: connect from 210.61.170.204
Oct 15 17:33:04 main ipop3d[28016]: connect from 163.31.21.45
Oct 15 23:02:43 main ipop3d[29903]: connect from 163.31.23.142
Oct 16 03:07:15 main login: DIALUP AT ttyS1 BY roger
Oct 16 03:07:15 main login: LOGIN ON ttyS1 BY roger
Oct 16 09:44:33 main ipop3d[2083]: connect from 10.1.2.4
Oct 16 19:55:03 main ipop3d[2271]: connect from 10.1.2.1
Oct 16 15:58:32 main ipop3d[2299]: connect from 10.2.1.103
Oct 17 08:50:11 main in.ftpd[6255]: connect from 163.31.19.169
Oct 17 12:01:35 main ipop3d[6348]: connect from 10.1.4.2
Oct 17 14:19:43 main in.ftpd[6504]: connect from 163.31.23.91
Desired Output
Oct 16 03:07:15 main login: DIALUP AT ttyS1 BY roger
Oct 16 03:07:15 main login: LOGIN ON ttyS1 BY roger
Oct 16 09:44:33 main ipop3d[2083]: connect from 10.1.2.4
Oct 16 19:55:03 main ipop3d[2271]: connect from 10.1.2.1
Oct 16 15:58:32 main ipop3d[2299]: connect from 10.2.1.103
Oct 17 08:50:11 main in.ftpd[6255]: connect from 163.31.19.169
Oct 17 12:01:35 main ipop3d[6348]: connect from 10.1.4.2
Oct 17 14:19:43 main in.ftpd[6504]: connect from 163.31.23.91