0

I have a text file with several lines. In every line there appears a certain string either once or several times. I want to extract all lines where the string appears more than once and write these lines to a separate text file.

My attempt would go over regular expressions and I would do find & replace in UltraEdit. How would the RegEx in UltraEdit look like?

Zappi
  • 13
  • 5

2 Answers2

0

I'm not sure about UltraEdit, but this is easy grep-able. grep .*STRING.*STRING.* myfile.file > output.file

This will search myfile.file for any line with two occurrences of STRING and outputs it to the file output.file.

If Windows, use findstr .*STRING.*STRING.* myfile.file > output.file. Same result, check output.file for the full lines that contain two (or more) occurrences of STRING.

kirkpatt
  • 625
  • 5
  • 21
0

There are 3 regular expression engines available in UltraEdit for Windows since v12.00.

The regular expression is simple on using any of the three expressions.

UltraEdit regular expression search string: string?+string

? does not match newline characters. So a line must contain string twice with other characters except newline characters between.

Unix or Perl regular expression search string: string.+string

. does not match newline characters (by default). So a line must contain string twice with other characters except newline characters between.

With Perl it is also possible to use \bstring\b.+\bstring\b if a positive match should require that string is a complete word excluding for example a line containing strings or substring.

The lines producing a positive match can be written to Find String List window with find option List lines containing string checked and copied from this window via context menu into a new file.

It is also possible to use find option Filter lines with Show selected to get displayed only lines containing string at least two times.

Further a Find in Files with option Open files selected and option Results to edit window checked can be executed to get the found lines into a new file without or with additional information according to configuration as defined at Advanced - Settings or Configuration - Search - Set Find Output Format. Of course it is also possible to run same Find in Files without option Results to edit window checked to get the found lines written to active output window tab.

And there are UltraEdit scripts documented at Find strings with a regular expression and output them to new file to grep from active file strings using a regular expression into a new file.

Mofi
  • 46,139
  • 17
  • 80
  • 143