grep- Delete everything in each line before a specific character

1,665 views
Skip to first unread message

Randy Roberts

unread,
Aug 29, 2014, 12:59:38 PM8/29/14
to bbe...@googlegroups.com
I have some files the look like this:

    <thumb fileName="I1092_LS_ChxBS_IT_Bollard.jpg">Bacon Ranch Chicken Sandwich with Iced Tea Suite</thumb>
    <thumb fileName="I1074_ESPRESSOLn_Bollard.jpg">Espresso Line</thumb>
    <thumb fileName="W_I1078_HotIcedLatte_Bollard.jpg">Hot and Iced Lattes</thumb>

There are thousands of lines but here are 3 of them. I need to select and delete everything from the beginning of the line up to the first instance of ">". The desired outcome would be:

>Bacon Ranch Chicken Sandwich with Iced Tea Suite</thumb>
>Espresso Line</thumb>
>Hot and Iced Lattes</thumb>

I have tried several expressions and none have worked.

Thanks for your help

RR

Rod Buchanan

unread,
Aug 29, 2014, 1:09:26 PM8/29/14
to bbe...@googlegroups.com
On Aug 29, 2014, at 11:59 AM, Randy Roberts <reall...@gmail.com> wrote:

I have some files the look like this:

    <thumb fileName="I1092_LS_ChxBS_IT_Bollard.jpg">Bacon Ranch Chicken Sandwich with Iced Tea Suite</thumb>
    <thumb fileName="I1074_ESPRESSOLn_Bollard.jpg">Espresso Line</thumb>
    <thumb fileName="W_I1078_HotIcedLatte_Bollard.jpg">Hot and Iced Lattes</thumb>

There are thousands of lines but here are 3 of them. I need to select and delete everything from the beginning of the line up to the first instance of ">". The desired outcome would be:

Search:
^.*?>

Replace:
>

-- 
Rod Buchanan
KDSI / Kelly Supply Co / ISCO
308 382-8764 x1120

Christopher Stone

unread,
Aug 30, 2014, 12:26:39 AM8/30/14
to BBEdit-Talk
On Aug 29, 2014, at 11:59, Randy Roberts <reall...@gmail.com> wrote:
<thumb fileName="I1092_LS_ChxBS_IT_Bollard.jpg">Bacon Ranch Chicken Sandwich with Iced Tea Suite</thumb>
...
There are thousands of lines but here are 3 of them. I need to select and delete everything from the beginning of the line up to the first instance of ">". The desired outcome would be:

>Bacon Ranch Chicken Sandwich with Iced Tea Suite</thumb>
______________________________________________________________________

Hey Randy,

You say some files, so I imagine you might want to automate the process a bit.

Of these the Perl filter is fastest on a really big file (above 50K lines).

----------------------------------------------------------------------
RegEx Find/Replace using Positive Lookahead Assertion
----------------------------------------------------------------------

Find:

^.+?(?=>)

Replace:

Nothing

----------------------------------------------------------------------
AppleScripted RegEx Find/Replace
----------------------------------------------------------------------

tell application "BBEdit"
  tell front text window's text
    replace "^.+?(?=>)" using "" options {search mode:grepcase sensitive:falsestarting at top:true}
  end tell
end tell

----------------------------------------------------------------------
Perl Text Filter
----------------------------------------------------------------------

#! /usr/bin/env perl 
use v5.010; use strict; use warnings;
while (<>) {
  if ( m!^.+?(?=>)(.+)! ) {
say $1;
} else {
print;
}
}

----------------------------------------------------------------------

To quickly get to your text filter folder if you haven't used it before paste the following line into a BBEdit worksheet or the Terminal and run.

D=~/'Library/Application Support/BBEdit/Text Filters/'; mkdir "$D" > /dev/null 2>&1; open "$D";

--
Best Regards,
Chris

Reply all
Reply to author
Forward
0 new messages