Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BBEdit GREP Find Replace

I'm working with a tab-delimited file in BBEdit. The file looks like this:

00:15:50;11     text1     text2
00:35:17;03     text4     text5
00:35:20;03     text6   
00:35:20;22     text7   

Basically, it has: Timecode Tab Text Tab Text Etc

I want to take the second line of timecode and add it after the first line. I want it to look like this:

00:15:50;11     00:35:17;03     text1     text2
00:35:17;03     00:35:20;03     text4     text5
00:35:20;03     00:35:20;22     text6
00:35:20;22     text7

I've tried using this piece of GREP code:

FIND:

`(?-m)([0-9][0-9][; :][0-9][0-9][; :][0-9][0-9][; :][0-9][0-9])(.*)\r([0-9][0-9][; :][0-9][0-9][; :][0-9][0-9][; :][0-9][0-9])`

REPLACE:

'\1\t\3\2\r\3'

My problem is that it only searches and replaces every other line. If I do a find/replace all, it looks like this:

00:15:50;11     00:35:17;03     text1     text2
00:35:17;03     text4     text5
00:35:20;03     00:35:20;22     text6
00:35:20;22     text7   

It's skipping every other line. I want to do a search/replace all in several hundred files. I'm wondering if there's something that I can change to make sure it gets every single line.

Thank you.

like image 663
basil Avatar asked May 15 '26 06:05

basil


1 Answers

I took your regex and modified it slightly.

The trick is to not match the Timecode at the beginning of the line. So, use Positive Lookbehind.

(?<=([0-9][0-9][; :][0-9][0-9][; :][0-9][0-9][; :][0-9][0-9]))  /*lookbehind to see if timecode exists, but dont match. 
                                                                But, the use of parenthesis makes it the first capture group.*/
(.*)
\r
([0-9][0-9][; :][0-9][0-9][; :][0-9][0-9][; :][0-9][0-9])

Before,

enter image description here

After,

enter image description here

like image 130
Noel Avatar answered May 19 '26 04:05

Noel