whh@jhunix.UUCP (William H. Huggins) (06/24/86)
One of the serious blunders that someone made in releasing the UNIX-PC software was the elimination of egrep and fgrep. (They simply made links to grep -- which is a swindle because egrep and fgrep do different things than grep in a REAL UNIX system). The program fgrep allows the user to specify not just one expression but multiple expressions one to a line, and it then finds lines that contain any of these expressions, e.g. $ fgrep ' expr1 expr2 expr3 ... ' files... This is more useful than grep, since one may not be able to state precisely ahead of time what strings to look for, but may desire any of several alternatives. Now, this can also be done using: $ sed -n ' /expr1/p /expr2/p /expr3/p ' file1 file2 file3 ... which prints any line that contains any of these three expressions. The trouble with this command is that, although it will print out the lines containing any of the three expressions, it will not print the name of the particular file in which they are located. So, let's use sed on just one file at a time. This can be done by the little shell program: for i in file1 file2 file3 ... do echo "In $i:" sed -n ' /expr1/p /expr2/p /expr3/p ' $i done which examines each of the files in order; prints out "In file1:" followed by any lines in file1 that match the given exprs; then examines file2, etc. This begins to resemble the missing program fgrep. So let's write a little shell program which we shall call 'fgrep' . It should look something like: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # fgrep -- emulates the 'real' fgrep for a single input file. case $# in 0) cat <<-endmsg Usage: fgrep expr1 [expr2 ...] file Prints lines of file that contain any of the expressions (ed-style syntax). endmsg exit ;; *) ;; esac # prepare sed program for finding expr1 expr2 etc. echo "sed -n '" >sed$$ while test "k$2" != "k" # There is yet another expression do echo "/$1/p">>sed$$ shift done echo "' $1" >>sed$$ # append file name to sed$$ program # execute sed$$ to search for exprs in file. . sed$$ rm sed$$ # remove temporary file sed$$ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ The above program writes the sed program needed to search for the desired exprs and then it runs the very program it has written. This shows how a little shell file using the Tools that are available can be written to do more useful things -- in this case to emulate the missing 'fgrep' command. -- W.H. Huggins
jrw@hropus.UUCP (Jim Webb) (06/25/86)
> One of the serious blunders that someone made in releasing the > UNIX-PC software was the elimination of egrep and fgrep. > (They simply made links to grep -- which is a swindle because > egrep and fgrep do different things than grep in a REAL UNIX > system). [insert nice shell programming here] > This shows how a little shell file using the Tools that are > available can be written to do more useful things -- in this > case to emulate the missing 'fgrep' command. Pretty neat, now how about egrep... -- Jim Webb ihnp4!houxm!hropus!jrw
corbin@cuuxb.UUCP (corbin) (06/26/86)
The ommission of fgrep and egrep will be remedied in the next release of software (3.5) for the UNIX PC. John Corbin (..!ihnp4!cuuxb!corbin)
kathy@bakerst.UUCP (Kathy Vincent) (07/04/86)
In article <734@cuuxb.UUCP>, corbin@cuuxb.UUCP (corbin) writes: > > The ommission of fgrep and egrep will be remedied in the next release of > software (3.5) for the UNIX PC. Will that version be available to the Real World? -- Kathy Vincent ========================================================== Home at _______________ / \ / kitty \ ihnp4! < > !bakerst!kathy wruxi / / mcnc!ethos! -------- AT&T at ihnp4!wruxi!unix