Grep Pattern Needed

32 views
Skip to first unread message

Kim Mosley

unread,
Sep 28, 2021, 2:05:09 PM9/28/21
to BBEdit Talk
I'm looking for a grep pattern to put this data into 5 columns (though there is no data for the "tags" column). Hopefully I can paste it into Excel. Now it just goes into one column.

Date
Description
Category
Tags
Amount
9/28/2021
Central Market
Groceries
-$45.28
9/28/2021
Randalls
Groceries
-$9.73
9/28/2021
Natural Grocers
Groceries
-$22.09
9/27/2021
Randalls
Groceries
-$11.03
9/27/2021
Amazon
General Merchandise
-$14.52
9/27/2021
Amazon
General Merchandise
$27.19
9/26/2021

Corentin Cras-Méneur

unread,
Sep 28, 2021, 2:19:12 PM9/28/21
to 'Dmitry Markman' via BBEdit Talk
Since you have more headers than fields, I’d remove the headers and I’d use (replace all):


Find: (.*)\r(.*)\r(.*)\r(.*)\r
Replace: \1\t\2\t\3\t\t\4\r

(Although I noted that the sample data you provided has a date at the end with no data for any of the other fields)

Corentin


--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/7a081d46-77cf-40a7-9ea3-d815ad80dd51n%40googlegroups.com.

John Delacour

unread,
Sep 29, 2021, 9:38:02 AM9/29/21
to bbe...@googlegroups.com


On 28 Sep 2021, at 19:04, Kim Mosley <mrkim...@gmail.com> wrote:

I'm looking for a grep pattern to put this data into 5 columns (though there is no data for the "tags" column). Hopefully I can paste it into Excel. Now it just goes into one column.

Save this script as xx.pl in
"~/Library/Application Support/BBEdit/Text Filters/",
bring your document to the front and run the filter from the palette (Menu: Window::Palettes::Text Filters.)

If you want to see the output without modifying the file, run the same script from the Scripts palette after saving it in the .../BBEdit/Scripts folder; otherwise just undo the work of the filter.


#!/usr/bin/perl
my $counter = 0; my $max = 5;
while (<>) { #read rows in succession
$counter++;
chomp; #remove linefeed
print "\t" if $counter == 4 && $max == 4; #skip a column
print; #add contents to column
if ($counter < $max) {
print "\t";
} else { #start a new row
print $/;
$counter = 0;
$max = 4; #allow for the missing tags data
}
}
#END

Let us know if there's any problem.

JD


Reply all
Reply to author
Forward
0 new messages