[aklug] Re: Q for grep geeks

From: James Zuelow <e5z8652@zuelow.net>
Date: Tue Aug 26 2008 - 22:04:46 AKDT

On Tuesday 26 August 2008 21:46:20 bryanm@acsalaska.net wrote:
> How can I match a doubled character, like the "ll" in sallied?
> I tried .{2} with egrep, but that just reduces to .. (any two
> characters).
>
> --
> Bryan Medsker
> bryanm@acsalaska.net

Use a back reference:

james@Samoa:~$ echo "sallied" | egrep -o ll
ll
james@Samoa:~$ echo "sallied" | egrep -o [[:alpha:]]{2}
sa
ll
ie
james@Samoa:~$ echo "sallied" | egrep -o "([[:alpha:]]+)\\1"
ll
james@Samoa:~$ echo "taffy" | egrep -o "([[:alpha:]]+)\\1"
ff
james@Samoa:~$ echo "f&&der" | egrep -o "(.+)\\1"
&&
james@Samoa:~$ echo "sallied" | egrep -o "(.+)\\1"
ll
                                              
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Tue Aug 26 22:05:07 2008

This archive was generated by hypermail 2.1.8 : Tue Aug 26 2008 - 22:05:07 AKDT