Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #176434 > unrolled thread
| Started by | Hans <hans.ullrich@loop.de> |
|---|---|
| First post | 2017-01-08 10:20 +0100 |
| Last post | 2017-01-08 11:30 +0100 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.debian.user
Little question grep Hans <hans.ullrich@loop.de> - 2017-01-08 10:20 +0100
Re: Little question grep Reco <recoverym4n@gmail.com> - 2017-01-08 10:50 +0100
Re: Little question grep Reco <recoverym4n@gmail.com> - 2017-01-08 10:50 +0100
Re: Little question grep "John L. Ries" <jries@salford-systems.com> - 2017-01-08 11:30 +0100
| From | Hans <hans.ullrich@loop.de> |
|---|---|
| Date | 2017-01-08 10:20 +0100 |
| Subject | Little question grep |
| Message-ID | <sXhNT-4pM-3@gated-at.bofh.it> |
[Multipart message — attachments visible in raw view] — view raw
Hi all,
I have a little problem with using grep.
The problem:
I have a wordlist with 3,5 Mio words in ASCII. No I want filter out all words with 5,6,
7, 8, 9 and 10 signs in seperate lists. The wordlist contains all sort of signs, like
alphanumeric, control signs like "^", "]" and others.
So it must be same, whatever sign grep reads. I found this:
grep -o -w -E '^[[:alnum:]]{5}' file1
But it looks like it is only grepping text. I read the manual of grep, and I see, there
are more options to chose. But I did not completely understand, if I have to chose
every option in addition or if is there an option,which covers every kind of sign.
Would be nice, if someone could make this a little bit brighter for me.
Thank you for any hints.
Best regards
Hans
[toc] | [next] | [standalone]
| From | Reco <recoverym4n@gmail.com> |
|---|---|
| Date | 2017-01-08 10:50 +0100 |
| Message-ID | <sXigV-4z0-11@gated-at.bofh.it> |
| In reply to | #176434 |
On Sun, 8 Jan 2017 12:40:34 +0300
Reco <recoverym4n@gmail.com> wrote:
> or, if you need whole words (i.e. need to exclude spaces):
>
> egrep '^[^ ]$' file1
Self-edit. Of course it's:
egrep '^[^ ]{5}$' file1
Reco
[toc] | [prev] | [next] | [standalone]
| From | Reco <recoverym4n@gmail.com> |
|---|---|
| Date | 2017-01-08 10:50 +0100 |
| Message-ID | <sXigV-4z0-13@gated-at.bofh.it> |
| In reply to | #176434 |
Hi.
On Sun, 08 Jan 2017 10:11:26 +0100
Hans <hans.ullrich@loop.de> wrote:
> Hi all,
>
> I have a little problem with using grep.
>
> The problem:
>
> I have a wordlist with 3,5 Mio words in ASCII. No I want filter out all words with 5,6,
> 7, 8, 9 and 10 signs in seperate lists. The wordlist contains all sort of signs, like
> alphanumeric, control signs like "^", "]" and others.
> So it must be same, whatever sign grep reads. I found this:
>
> grep -o -w -E '^[[:alnum:]]{5}' file1
>
>
> But it looks like it is only grepping text. I read the manual of grep, and I see, there
> are more options to chose. But I did not completely understand, if I have to chose
> every option in addition or if is there an option,which covers every kind of sign.
As it should be. regex(7) specifies that character classes are defined
in wctype(3), which states that '[[:alnum:]]' merely implements isalnum
(3), which, in turn is defined as (isalpha(c) || isdigit(c)).
So, what you really need is for five characters only (note final '$'):
egrep '^.{5}$' file1
or, if you need whole words (i.e. need to exclude spaces):
egrep '^[^ ]$' file1
Reco
[toc] | [prev] | [next] | [standalone]
| From | "John L. Ries" <jries@salford-systems.com> |
|---|---|
| Date | 2017-01-08 11:30 +0100 |
| Message-ID | <sXiTD-583-3@gated-at.bofh.it> |
| In reply to | #176434 |
That strikes me as being just a touch too complex for grep. It may well
be doable, but you'll probably have an easier time using AWK (possibly not
what you wanted to hear, but it's well worth learning). The object of the
game would be to count the number of signs on each line and print only
those with the specified number. Then in a shell script (my preferred
poison is ksh) set up a loop like so:
#Not guaranteed to be syntactically correct
for ((i=5; i<=10; i++)); do
awk -f ctsign.awk N=$i biglist.txt >${i}signs.txt
done
Or one can use such scripting languages as Perl or Python to do the whole
job.
Hope it helps...
--------------------------|
John L. Ries |
Salford Systems |
Phone: (619)543-8880 x107 |
or (435)867-8885 |
--------------------------|
On Sun, 8 Jan 2017, Hans wrote:
>
> Hi all,
>
>
>
> I have a little problem with using grep.
>
>
>
> The problem:
>
>
>
> I have a wordlist with 3,5 Mio words in ASCII. No I want filter out all
> words with 5,6, 7, 8, 9 and 10 signs in seperate lists. The wordlist
> contains all sort of signs, like alphanumeric, control signs like "^", "]"
> and others.
>
> So it must be same, whatever sign grep reads. I found this:
>
>
>
> grep -o -w -E '^[[:alnum:]]{5}' file1
>
>
>
> But it looks like it is only grepping text. I read the manual of grep, and I
> see, there are more options to chose. But I did not completely understand,
> if I have to chose every option in addition or if is there an option,which
> covers every kind of sign.
>
>
>
> Would be nice, if someone could make this a little bit brighter for me.
>
>
>
> Thank you for any hints.
>
>
>
> Best regards
>
>
>
> Hans
>
>
>
>
>
>
>
[toc] | [prev] | [standalone]
Back to top | Article view | linux.debian.user
csiph-web