Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Generate words that contain only a certain character set

5 views
Skip to first unread message

Janis Papanagnou

unread,
Sep 23, 2021, 5:08:27 AM9/23/21
to
On 23.09.21 09:23, Ottavio Caruso wrote:
> Hi,
>
> 1) is there a Unix/Linux program that can generate words (not random
> characters) out of a set of characters (say: "5.tpiuongf"). If this
> doesn't exist:
>
> 2) Is it possible to write a script that does the above out of, for
> example, /usr/share/dict/* ?
>
> So, I want to find all lines that contain _only_ one or more of any of
> "5.tpiuongf".
>
> Naively, I started experimenting with [e]grep but I suspect it's not the
> right way.

Well, in the past I had used to use awk for that, as in

awk '!/[^5.tpiuongf]/'

(i.e. working with double negation).

Janis

Janis Papanagnou

unread,
Sep 23, 2021, 5:15:17 AM9/23/21
to
Using grep with the same logic is of course also possible

grep -v '[^5.tpiuongf]'

> Janis
>

Andy Walker

unread,
Sep 23, 2021, 8:33:55 AM9/23/21
to
On 23/09/2021 10:15, Janis Papanagnou wrote:
> Using grep with the same logic is of course also possible
> grep -v '[^5.tpiuongf]'

FWIW,

grep '^[5.tpiuongf]*$'

works here, and is one character shorter.

--
Andy Walker, Nottingham.
Andy's music pages: www.cuboid.me.uk/andy/Music
Composer of the day: www.cuboid.me.uk/andy/Music/Composers/Jessel

Ed Morton

unread,
Sep 23, 2021, 9:03:24 AM9/23/21
to
On 9/23/2021 2:23 AM, Ottavio Caruso wrote:
> Hi,
>
> 1) is there a Unix/Linux program that can generate words (not random
> characters) out of a set of characters (say: "5.tpiuongf"). If this
> doesn't exist:
>
> 2) Is it possible to write a script that does the above out of, for
> example, /usr/share/dict/* ?
>
> So, I want to find all lines that contain _only_ one or more of any of
> "5.tpiuongf".
>
> Naively, I started experimenting with [e]grep but I suspect it's not the
> right way.
>

I'm trying to understand what you mean by "word" and the difference
between a "word" and a string of random characters to you.

Can you define "word" in your context and give examples of words that
contain "." and/or "5"?

Do you just want a script that will generate random combinations of a
specific set of characters as opposed to random combinations of all
characters?

If so is there any limit to how long those strings could be or how many
times 1 character can repeat or how many of the target characters the
string has to contain or how close duplicates of each character can be
to each other or requirements to contain some vowels or anything else?

Ed.

Janis Papanagnou

unread,
Sep 23, 2021, 10:09:51 AM9/23/21
to
On 23.09.21 15:16, Ottavio Caruso wrote:
> On 23/09/2021 13:33, Andy Walker wrote:
>> On 23/09/2021 10:15, Janis Papanagnou wrote:
>>> Using grep with the same logic is of course also possible
>>>    grep -v '[^5.tpiuongf]'
>>
>> FWIW,
>>
>>       grep '^[5.tpiuongf]*$'
>>
>> works here, and is one character shorter.
>>
>
> Fantastic, that's exactly what I was looking for.
>
> One question: do I not have to escape the dot [.]?

Not if it's inside the [].

(You can test that it's not matching "any character" here.)

Janis
0 new messages