Simply replace a complete line

General discussions about Advanced Find and Replace
Post Reply
Mc2102
Posts: 5
Joined: Mon Feb 12, 2007 11:34 pm

Simply replace a complete line

Post by Mc2102 » Mon Feb 12, 2007 11:40 pm

Hello,

I have a ldif file with 90 000 users in it. So there are 90 000 lines in that file which contain the following string

userpassword: <some password>

<somepassword> is filled of course with the user password which contains numbers and letters.
What I need to do is to replace the complete line with the following string

userpassword: XXXXXX

I cannot figure out to get that accomplished.

Abacre
Site Admin
Posts: 1198
Joined: Mon Jan 31, 2005 5:32 pm
Contact:

Post by Abacre » Tue Feb 13, 2007 9:39 am

Go to main menu - Action - Options - Batch Replace
uncheck "Modifier S"
check "Modifier G"

Go to Batch replace tab, check on "Use regular expressions".
Put into the grid, search for:
userpassword: \w+

Replace with:
userpassword: XXXXXX

That's all I verified it works perfectly.

Explanations:
\w means an alphanumeric character (including "_")
\w+ means one and more alphanumeric characters.
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

Mc2102
Posts: 5
Joined: Mon Feb 12, 2007 11:34 pm

Post by Mc2102 » Tue Feb 13, 2007 4:53 pm

Roman,

Thanks for the quick response.

Acullay 'userpassword: \w+' dit not do the trick.

Example: I have the following line

userPassword: 12345678910

'userpassword: \w+' would do the following:

userPassword: XXXXX2345678910

As you can see it would only remove the first number.

So I used 'userpassword: \w\w\w\w\w\w\w\w\w\w\'

Because the passwords have exact 10 numbers.

So how would I have to write it the search string if I want to remove the complete 'userPassword: 12345678910' ?
And where can I read about those expressions. For example I would be intrested in what I have to use if I look for letter and not numbers.
I had a look into the programs help section but I couldn't find there anything.

Abacre
Site Admin
Posts: 1198
Joined: Mon Jan 31, 2005 5:32 pm
Contact:

Post by Abacre » Tue Feb 13, 2007 5:05 pm

Mc2102 wrote:'userpassword: \w+' would do the following:

userPassword: XXXXX2345678910

As you can see it would only remove the first number.

This is because you forgot to check "Modifier G" (greedy mode).

Mc2102 wrote:
So I used 'userpassword: \w\w\w\w\w\w\w\w\w\w\'

Because the passwords have exact 10 numbers.

You can do it this way too:
userpassword: \w{10}

But note: \w means an alphanumeric character. It means that it
contains letters a..zA..Z and digits 0..9
BTW instead of \w you can use [a..zA..Z0..9_]
for example:
userpassword: [a..zA..Z0..9_]{10}


If you want to search only for digits (numbers) you have to use:
userpassword: \d{10}

Where \d means a digit.

Mc2102 wrote:So how would I have to write it the search string if I want to remove the complete 'userPassword: 12345678910' ?

It's simple. In order to remove found text the Replace With text
should be empty. So clear the Replace With text.

Mc2102 wrote:And where can I read about those expressions. For example I would be intrested in what I have to use if I look for letter and not numbers.
I had a look into the programs help section but I couldn't find there anything.

Please read the page of the documentation:
http://www.abacre.com/afr/manual/regexpsyntax.htm
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

Abacre
Site Admin
Posts: 1198
Joined: Mon Jan 31, 2005 5:32 pm
Contact:

Post by Abacre » Tue Feb 13, 2007 5:22 pm

Roman wrote:
Mc2102 wrote:So how would I have to write it the search string if I want to remove the complete 'userPassword: 12345678910' ?

It's simple. In order to remove found text the Replace With text
should be empty. So clear the Replace With text.

BTW if you want to remove a whole line you should use:
userpassword: \w{10}\r\n

Where \r\n means end of line.
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

Mc2102
Posts: 5
Joined: Mon Feb 12, 2007 11:34 pm

Post by Mc2102 » Tue Feb 13, 2007 5:46 pm

You are right. I did not check "g". My bad. Sorry about this.

Thank you so much for your help

Marcus

Mc2102
Posts: 5
Joined: Mon Feb 12, 2007 11:34 pm

Post by Mc2102 » Wed Feb 14, 2007 2:19 pm

After I have tested the syntax and of course it works as you say I have now the problem that I run this Replace command against my 65MB.txt file and I can see that "Advanced Find and Replace" takes up all the CPU and lots of memory but it is running now for 12 hours and nothing happened.
Is there any way tho speed things up?

Abacre
Site Admin
Posts: 1198
Joined: Mon Jan 31, 2005 5:32 pm
Contact:

Post by Abacre » Wed Feb 14, 2007 2:36 pm

Do you mean Replace or Batch Replace command? I think you are talking
about Batch Replace.

I forgot to say: for intensive search/replace operations it's better to
uncheck "Make Preview" option located in main menu - Action - Options
- Preview. Making the preview consumes a lot of memory and it
significantly slows down the search/replace operations. Sometimes AFR
replaces without preview several times faster than with enabled "Make
Preview" option. But it will take all CPU time anyway. In future
version we will make an option for specify how much CPU time should be
consumed.

So please uncheck "Make Preview" option and try again.

In case if it's still running after 12-24 hours please zip your data
file send it to support@abacre.com together with your default.cfg file
located in installation folder.
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

Mc2102
Posts: 5
Joined: Mon Feb 12, 2007 11:34 pm

Post by Mc2102 » Wed Feb 14, 2007 3:19 pm

Roman, first i want to say how much I appriciate your help on this.

I disabled the "make review" option and I also disabled the "ask before replacing" function and the tool is running now since about 30 min but has not modified one line in the file. But it keeps the machine busy - what is it doing ? :D

Abacre
Site Admin
Posts: 1198
Joined: Mon Jan 31, 2005 5:32 pm
Contact:

Post by Abacre » Wed Feb 14, 2007 3:23 pm

Wait until the end of replace operation. Because the file will be
updated only after all replacements are done.
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests