Xref: utzoo comp.unix.wizards:9011 comp.unix.questions:7343 Path: utzoo!attcan!uunet!mcvax!ukc!stc!root44!gwc From: gwc@root.co.uk (Geoff Clare) Newsgroups: comp.unix.wizards,comp.unix.questions Subject: Re: grep replacement Summary: Use sed! Message-ID: <590@root44.co.uk> Date: 31 May 88 13:01:07 GMT References: <7882@alice.UUCP> Reply-To: gwc@root.co.uk (Geoff Clare) Organization: UniSoft Ltd, London, England Lines: 27 Most of the useful things people have been saying they would like to be able to do with 'grep' can already be done very simply with 'sed'. For example: Stop after first match: sed -n '/pattern/{p;q;}' Match over two lines: sed -n 'N;/pat1\npat2/p;D' It should also be possible to get a small number of context lines by judicious use of the 'hold space' commands (g, G, h, H, x), but I haven't tried it. Anyway, this can be done with a normal line editor (if the data to be searched aren't coming from a pipe) with 'g/pattern/-,+p'. I was rather alarmed to see the proposal for 'pattern repeat' in the original article was '\{pattern\}\1' rather than '\(pattern\)\1', as the latter is already used for this purpose in the standard editors (ed, ex/vi, sed). Or was it a typo? By the way, does anyone know why the ';' command terminator in 'sed' is not documented? It works on all the systems I've tried it on, but I have never found it in any manuals. It's so much nicer than putting the commands on separate lines, or using multiple '-e' options. -- Geoff Clare UniSoft Limited, Saunderson House, Hayne Street, London EC1A 9HH gwc@root.co.uk ...!mcvax!ukc!root44!gwc +44-1-606-7799 FAX: +44-1-726-2750