I was trying many different combinations without success, at this point I would be really grateful for your help.

I need to replace this end of the line multiple times (around 300) and it would be painful to replace it one by one:

:;XXXXXX (lenght may vary)

I was able to find it with :;*$ which highlights exactly what I need! But I'm unable to replace it, to make it look like this: :;XXXXXX;;;

* - is supposed to match anything (and it does)

$ - is supposed to match end of the line (and it does)

I've tried encapsulating * in brackets (*); [*]...like :;(*);;;$ among other things, but to no avail. Of course replacement is made, but in the same form as input. For example... instead of :;XXXXXX;;; I get :;*;;; - and that is the best I was able to get out of it.

This is UltraEdit regular expression format, but this piece of software can process Unix and Perl regular expressions as well.

I you can suggest ANY way to do this, I will give it a try (terminal, another software etc.).


I'm trying to get contacts from old nokia to newer nokia (s30+ series). There was only backup.nbu from which I got .vcf contacts. I have put them to one file via cat *.vcf > combined.vcf. I've found Excel macro and PHP script which were supposed to do the whole process, but they didn'work - but all this is not that relevant I guess. After that I have found Vcard format this particular model can process. Now I'm trying to modify it, to look the same. Replacing lines was no problem, but I need to edit ends. ;:NAME to ;:NAME;;; without modifying names...

I tried what I've described above. After that I've tried suggested sed -ri "s/\:\;X+$/&\;\;\;/g".

I tough that DOS ends of the lines might be the problem, so I ran:sed -i 's/\r//g' combined.vcf and then again the suggested sid command.




So I went from the beginning...

  1. I've combined .vcf files

  2. Opened them in UltraEdit and saved as LF (from CRLF) - tried this time without sed and terminal

  3. In find replace I've selected Perl Regex

    • Find (:;)(.*)

    • Replace \1\2;;;

For reference: .* - Match zero or more of any characters (except new line)...


  • 1
    Congrats on solving your issue, but we don't use SOLVED on this site, mark the answer that solves/answers your question as the answer and use the votes when you have the rep. I believe SOLVED is used on forums so I understand where you have it from. Commented Jun 6, 2015 at 14:12

2 Answers 2


What you need is called the back-references. It means "put here whatever was selected in the match" and functions by:

  1. Using parenthesis in the matching regex to select a part of the string,
  2. Using a numbered back-reference (\1 for the first parenthesis, \2 for the second one, etc.).

sed support this and this produces the following command (sed requires the parenthesis to be escaped, but this may not be the case for other regex based software):

sed -i 's/^\(:;.*\)$/\1;;;/' combined.vcf
  • Selected for getting me on track with back-reference!!! Thank you mate! I will provide solution in my question... Commented Jun 6, 2015 at 11:53

Using sed this can done like this:

echo ":;XXXXXX" | sed -re "s/\:\;X+$/&\;\;\;/g"

As you are taking the data from some file, you can directly edit it inside file using:

sed -ri "s/\:\;X+$/&\;\;\;/g" file.txt
  • It didn't work for me :/. I will provide more info in my question asap! Commented Jun 6, 2015 at 10:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .