Page 1 of 1

Replace text with blanks

Posted: Fri Dec 07, 2007 10:27 pm
by Vauh
I get regularly a document with technical data mostly numbers in rows.
I wish to replace all text which is in between these numbers, with the same amount of blanks, to keep the numbers in a row.

How can I do that?

Example: NO ELEMENTS AVAILABLE = 21 bytes should be replaced by 21 blanks.

or other example

SELENOCENTRIC ORBIT = 19 bytes should be replaces by 19 blanks

and so on.

This is a list with over 35.000 lines and about 150 text parts which I need to replace.


Thanks for your help.

Vauh

Posted: Fri Dec 07, 2007 11:52 pm
by ben_josephs
It depends on what exactly you mean by a number.

If you just want to replace every character that isn't a digit, a dot, a comma or a minus sign by a space, you can use this:
Find what: [^0-9.,-]
Replace with: [a space]

[X] Regular expression

Replace All
If you need to distinguish between dots and commas in numbers from dots and commas elsewhere, it's a bit trickier.

Posted: Sat Dec 08, 2007 5:03 pm
by Vauh
Thanks for your message.
But, unfortunately, this is not, what I want to do.
There are letters, I don't want to replace.

I put in the search option, what I wish to delete and to replace by blanks.
But, I don't want every time to put in the replace section 20 ore more times a blank using the space bar.

Example:
Search: NO ELEMENTS AVAILABLE = 21 bytes
Replace: 21 times space bar

This is what I do now!!!!!

How I can make this easier?

Thanks for your help.

Vauh

Posted: Sun Dec 09, 2007 8:48 pm
by ben_josephs
Unfortunately, you can't do this with TextPad.

But you can easily do it with a script in any of many popular free scripting languages such as Perl, Python, Ruby or Tcl. For example, you can use this Perl one-liner on the Windows command line:

Code: Select all

perl -i.bak -p -e "s/NO ELEMENTS AVAILABLE/' ' x length $&/e" filename