0

I have loads of files that need to contain the name

Jacqueline

But instead, they contain the following:

Jacquelin

but also sometimes

fooJacquelinbar or

123Jacquelin123 or

/Jacquelin/

How do I replace every instance of Jacquelin with Jacqueline, without ending up with things like Jacquelinee?

What I've tried is:

find . -name '*' -type f -exec sed -i 's/\bJacquelin\b/Jacqueline/g' {} +

But this will not replace instances where anything is attached to "Jacquelin" (doesn't match the whole word).

4

Try also

sed  's/\(Jacquelin\)e\?/\1e/g' file

or

sed -r 's/(Jacquelin)e?/\1e/g' file
1

I would recommend using Perl to utilise negative look-aheads

perl -pe 's/Jacquelin(?!e)/Jacqueline/g'

which will replace when Jacquelin is not immediately followed by the character e (this includes if there isn't a character after)

To batch edit files in-place, you can add the -i flag:

find . -name '*' -type f -exec perl -pi -e 's/Jacquelin(?!e)/Jacqueline/g' {} +

Remember to backup before hand as the operation isn't reversible

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.