Re: Help with a grep question

2018-02-04 Thread Christopher Stone
On 01/26/2018, at 20:56, Doug Lerner mailto:d...@lerner.net>> 
wrote:
> What I would like to do is find everything between the ID_User_ and *-find 
> (e.g. .5a82483a in this example) and be left with a file where each line 
> contains just that userId. After that I can sort it, remove duplicates, etc.
> 
> Is there a sequence of things I can do, using grep search patterns, and so 
> on, to create a file from this file containing just the userIds?


Hey Doug,

This is the sort of job Perl is very good at.


#!/usr/bin/env perl -sw
use v5.010;
use open qw(:std :utf8);
use utf8;
# 
# Auth: Christopher Stone
# dCre: 2018/02/04 22:00
# dMod: 2018/02/04 22:16 
# Task: Find a regular expression per line, sort, and remove duplicates.
# Tags: @Shell, @Script, @Find, @Regular, @Expression, @Per, @Line, @Sort, 
@Remove, @Duplicates
# 

my (@Array, @Unique, %Hash, $Key);

while (<>) {
if ( /ID_User=(.*?)-find/ ) {
$Hash{$1} = 1;
}
}

foreach $Key (sort keys %Hash) {
say $Key;
}


The script processes a 100,000 line file in about a second on my old 2010 
MacBook Pro.


Now just for fun let's try that with a 1-line Bash script.


#!/usr/bin/env bash
LC_ALL='C'

sed -En '/ID_User=.*-find/{ s!ID_User=(.*)-find!\1!;p; }' | sort -u


Run either one of these as a BBEdit text-filter 
.

If you want to keep the original data file then run on a copy.

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or would like to report a problem, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.


Re: Help with a grep question

2018-01-28 Thread Dave
Enter one of these patterns in a Find dialog:
(?<=ID_User=)\.[[:xdigit:]]+(?=&-find)
or
(?<=ID_User=)\.[[:alnum:]]+(?=&-find)
(Which pattern depends on whether the ID is a hexadecimal number or simply 
a sequence of alphanumeric characters.)
Click Extract.
A new document containing the IDs will be created. The (?…) patterns (known 
as positional assertions) are not captured.

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or would like to report a problem, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.


Re: Help with a grep question

2018-01-27 Thread Fletcher Sandbeck
Select "Process Lines Containing" from the Text menu. Use an expression like 
"ID_User" and the "Copy to new document" option. This will create a new 
document that contains only lines that you want to process.

Then a simple replace all should do the actual work.

Find: .*ID_User=(.+?)&.*\r
Replace: \1\r

Hope this helps,

[fletcher]


> On Jan 26, 2018, at 6:56 PM, Doug Lerner  wrote:
> 
> Hi. I am using BBEdit 11.6.8 and have a file with thousands of lines, where 
> most lines contain an expression that looks like this:
> 
> ID_User=.5a82483a&-find
> 
> There's other stuff on the line too.
> 
> What I would like to do is find everything between the ID_User_ and *-find 
> (e.g. .5a82483a in this example) and be left with a file where each line 
> contains just that userId. After that I can sort it, remove duplicates, etc.
> 
> Is there a sequence of things I can do, using grep search patterns, and so 
> on, to create a file from this file containing just the userIds?
> 
> Thanks,
> 
> doug
> 
> -- 
> This is the BBEdit Talk public discussion group. If you have a 
> feature request or would like to report a problem, please email
> "supp...@barebones.com" rather than posting to the group.
> Follow @bbedit on Twitter:  >
> --- 
> 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+unsubscr...@googlegroups.com 
> .
> To post to this group, send email to bbedit@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/bbedit 
> .

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or would like to report a problem, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.