Searching for lines that contain both of 2 strings

A user called to ask whether there's a way to do this in host-based Qedit:
List lines that contain a string, within a rangelist of lines that contain another string. e.g. He wants to list lines that contain the string "var" as well as the string "boolean" He knows that he can use patternmatching, but then it'll list only lines with the strings in one sequence ("@var@boolean@" OR "@boolean@var@").

Here is one solution. Qedit has the OR operator to find lines that contain either of the lines (e.g., /list "var" or "boolean"). So you could use it to search for either of the patterns listed above. For example:

/list "@var@boolean@" OR "@boolean@var@"

Here's another workaround, in 3 steps:

  /cha 1 \$\ \boolean\(ups)   {insert a "$" in column 1 if line contains first string}
  /l \$@var@\(pat ups)        {search for "$ lines" that contain second string}
  /cha 1/1 \\ \boolean\(ups)  {remove "$" characters}

But, here is the shortest one:

  /c "foo"foo" "blah"
This will list all of the strings that contain "foo" and "blah". (It will change them, too, so no browse mode here.)

You'd need to be sure that Upshifted string searching is not on, so that you don't end up changing lines you don't expect to change. BUT as part of the workaround, you could do an UNDO. You could even package this into a command file:

parm string1
parm string2
/change "!string1","!string1","!string2"
if qeditcount > 0 then
/undoq
endif
/

....Back to the Qedit Q&A Page