Dave, Many thanks for your help.
Two items. First, when I say "variable text" I just mean that there can be text of any length between the "LEC" and the carriage return. But I'm confused when you say that Grep can't do replacements. I'm using this in the context of TextWrangler, and it's all about finding and replacing text. Maybe my newness is standing out here. . . . I will look up info on PERL and see if I can make your suggestion work. Grep can't do replacements. To do what you want, you need a tool like sed, awk or perl. Although you did not specify what you mean by "variable text" following "LEC" (or at least it's an ambiguous definition), I think the following perl code might do: perl -ne 'print if s/(LEC.*?(?:ulty|$))/($a=$1)=~s,\s,zzzz,g;$a/ge' Note that due to the ambiguous problem statement you provided, the above code might also turn out to be wrong for you. -- View this message in context: http://www.nabble.com/Simple-Grep-Command--tp25480399p25491973.html Sent from the Gnu - Grep mailing list archive at Nabble.com.
