[aklug] Re: sed regex help needed

From: Shane Spencer <shane@bogomip.com>
Date: Sat Nov 14 2009 - 15:27:20 AKST

Just make sure you grep for clean input data as well, but here's how I
would have generically found the data.

spencersr@lateralus:~$ echo "[43]: KB950974 - Update" | sed 's/.*:
\(.*\) - Update.*/\1/'
KB950974

spencersr@lateralus:~$ echo "[43]:
KB950974-32-45-55----209200234020340 - Update" | sed 's/.*: \(.*\) -
Update.*/\1/'
KB950974-32-45-55----209200234020340

Alternatively use awk:

spencersr@lateralus:~$ echo "[43]: KB950974 - Update" | awk '{print $2}'
KB950974

On Sat, Nov 14, 2009 at 3:09 PM, Lee <lee@afabco.org> wrote:
> heya folks,
>
> Been working on this for a while now, and decided it's time to call for a=
ssistance.
>
> I'm trying to use sed to extract an arbitrary length substring that begin=
s with KB and
> ends with =A0- =A0. =A0That's a space-dash.
>
> For example, given the line:
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 [43]: KB950974 - Upda=
te
>
>
> I want to extract the string KB950974
>
> and given the line:
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 [44]: KB951072-v2 - U=
pdate
>
> I want to extract the string KB951072-v2
>
> This is the only thing I've come close to that works:
>
> |sed -n -e "s/.*\(KB.\{6\}\).*/\1/p"
>
> but that's not right, because it limits the string extraction to KB and t=
he next six
> chars, with no end condition.
>
> I suspect that the dash requirement is screwing me over since it's a rese=
rved character.
> =A0But I'm at a loss.
>
> Thanks in advance!
>
>
> ---------
> To unsubscribe, send email to <aklug-request@aklug.org>
> with 'unsubscribe' in the message body.
>
>
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Sat Nov 14 15:27:39 2009

This archive was generated by hypermail 2.1.8 : Sat Nov 14 2009 - 15:27:39 AKST