2

I have a very long text file that contains records of data in a two lines format. Is there a way to simply replace all "newlines" characters to a space using IDM UltraEdit?

Sample input record (two lines):

OPCODE   { V { X1;  }
           W { all=set; } } 

needs to be re-formatted into a single line

OPCODE   { V { X1;  } W { all=set; } } 

I have tried using Ultraedit Find and Replace using a regular expression to catch the newline:

Regexp used: }[^n][ ]+W

Replace with: } W

But the result was (removing the white space characters before the second line)

OPCODE   { V { X1;  } 
W { all=set; } } 

I am using UltraEdit version 19.10.0.1016.

NirMH
  • 4,769
  • 3
  • 44
  • 69

1 Answers1

2

UltraEdit has 3 regular expression engines.

With the UltraEdit regular expression engine the search string can be either }[ ^t^r^n]+W or shorter }[ ^t^p]+W and the replace string is } W.

With the Unix regular expression engine the search string is }[ \t\r\n]+W and the replace string is also } W.

And with the most powerful Perl regular expression engine you have several options:

  1. The search string is \}[ \t\r\n]+W and the replace string is also } W.
    } must be escaped with a backslash in Perl regexp syntax in search string as otherwise the search string is invalid. This is most likely the fastest version.

  2. The search string is \}\s+W and replace string is } W.
    \s matches any whitespace character which includes also the newline control characters carriage return and line-feed and others in text files not very often used whitespaces from Unicode table. This is most likely slower than first option as the number of characters defined by \s is larger.

  3. The search string is (?<=\})\s+(?=W) and the replace string is just a single space character.
    (?<=\}) is a positive look-behind for } and (?=W) is a positive look-ahead for W. Look-behind and look-ahead make a search in general slower in comparison to a search avoiding it if that is possible.

  4. And lots of other search/replace expressions.

The case-sensitivity is controlled by Match case option in Replace dialog.

Mofi
  • 46,139
  • 17
  • 80
  • 143
  • Thanks - while all your regexp do find the pattern, the replace is not re-formating both lines into a single one - can you post an example (picture?) – NirMH Apr 12 '15 at 11:40
  • I tested all expressions before posting with UE v22.0.0.55. Now I tested them all also with UE v19.10.0.1012 restored from an archive. I do not have build 1016 of UE v19.10 archived. All replaces produced for your input block the expected one line output. Are you sure that the replace edit field does not contain a not visible line break at begin or end? UE supports also multi-line search/replace strings. Set input focus to replace edit field and hit key END. If caret is not blinking after `W`, you have an unwanted line break in replace string. And key HOME should result in caret left of `}`. – Mofi Apr 12 '15 at 11:58
  • You were right! looks like i did had an unwanted line break in the replace string - thanks for the help. – NirMH Apr 12 '15 at 12:58