2

I have the text

af_ZA_work_013_A;135.300;150.203;Spreker-A;;;[no-speech] #mm
af_ZA_work_013_A;135.300;150.207;Spreker-B;;;[no-speech] #something

I want to add .wav before the first ; in each line, so I would get

af_ZA_work_013_A.wav;135.300;150.203;Spreker-A;;;[no-speech] #mm
af_ZA_work_013_A.wav;135.300;150.207;Spreker-B;;;[no-speech] #something

How can I do this?

jeremysprofile
  • 10,028
  • 4
  • 33
  • 53
Jirr Sawaf
  • 133
  • 9
  • @TimBiegeleisen well no since I have the same data but different names. so I need to specifically find ; and add .wav in front of it. – Jirr Sawaf Oct 13 '20 at 02:15
  • @TimBiegeleisen thank you but it doesnt. it would give me ```af_ZA_work_013_A.wav;135.300.wav;150.203.wav;Spreker-A;;;[no-speech] #mm``` – Jirr Sawaf Oct 13 '20 at 02:18
  • Does this answer your question? [In Vim, how to search and replace in current line only?](https://stackoverflow.com/questions/46181488/in-vim-how-to-search-and-replace-in-current-line-only) – jeremysprofile Oct 13 '20 at 02:35
  • @jeremysprofile no it doesn't! Okay everyone so basically I need to find the first ```;``` and replace is with ```.wav;``` i don't care about the rest of the text. Please see the difference between input and output. Also I have to do it globally because I have multiple lines of data – Jirr Sawaf Oct 13 '20 at 02:36
  • 1
    You should edit the question when adding information to your question, rather than including it in a comment, so other answerers can see the full question. It is currently unclear whether you mean the first `;` in the file or in each line, since your example text is one line. – jeremysprofile Oct 13 '20 at 03:20
  • @jeremysprofile updated it with multiple lines! – Jirr Sawaf Oct 13 '20 at 03:37

1 Answers1

1

s/search_regex/replace_regex/ will linewise execute your find and replace.

By default, this is done only on the current line, and only on the first match of search_regex on the current line.

Prepending % (%s/search/replace/) will execute your find and replace on all lines in the file, doing at most one replacement per line. You can give ranges (1,3s will execute on lines 1-3) or other line modifiers, but this isn't relevant here.

Appending g (s/search/replace/g) will do multiple replaces per line. Again, not relevant here, but useful for other scenarios.

You can search for ; and replace with .wav; (there are ways to keep the search term and add to it using capture groups but for one static character it's faster to just retype it).

TL;DR: :%s/;/.wav;/ does what you want.

jeremysprofile
  • 10,028
  • 4
  • 33
  • 53