Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!oliveb!sun!gorodish!guy From: guy@gorodish.Sun.COM (Guy Harris) Newsgroups: comp.unix.questions Subject: Re: grep replacement Message-ID: <54818@sun.uucp> Date: 28 May 88 21:58:00 GMT References: <7882@alice.UUCP> <2450011@hpsal2.HP.COM> Sender: news@sun.uucp Lines: 14 > grep -n does this, but I'd like to see an option which ONLY prints the line > numbers where the pattern was found. I wouldn't - if you're only grepping one file, you can do it without such an option: grep -n | sed -n 's/\([0-9]*\):.*/\1/p' If you're grepping more than one file, you obviously have to decide what you want to do with the file name and the line number; once you do, just change the "sed" pattern appropriately (and note that if the list of files is variable, you either have to stick "/dev/null" in there to make sure the names are generated even if there's only one file or have the script distinguish between the one-file and >1-file cases; I seem to remember some indication that the new BTL research "grep" would have a flag to tell it always to give the file name).