Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following lines:


How to put quote before the comma?

I've tried the following so far:


so & here replaces the matched pattern...

share|improve this question

You can use something like:


It uses \( and \) to create selection group which is then referenced by \1 (which means first group) on the substitute side.

share|improve this answer

If you want to move the quota from place before the number to a place before the comma, then you can use grouping


or to put another quotation mark before the comma, just include it into the first group:

share|improve this answer
How is this answer different from Krzysztofs? – Bernhard Oct 28 '12 at 20:14

Usually I use macros for tasks like this.


will get the job done (note the <Esc> part is an escape key press, not 5 separate keys). Here is a break down:

  • qq starts recording a macro and assign it to the q key.
  • Ei'<Esc> goes to the end of the word and inserts the '.
  • 0j goes to the beginning of the next line.
  • q ends the recording.
  • 3@q plays the macro 3 times, applying the same thing to the other 3 lines.

Replace 3 with the number of lines that you have.

share|improve this answer

$ is the end of the line

share|improve this answer

Maybe you forgot to define the general form where you need this to work. To do just what you asked for without guessing, this is the most simple (lazy!) solution that works for your example input:


If you want to handle more complex cases too, you should write better examples including the most complex case where you need the pattern substitution to work, and ideally an example of the target output too.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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