PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > : cat | grep '^99\d' don't work
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

: cat | grep '^99\d' don't work

Réponse
 
LinkBack Outils de la discussion
Vieux 02/12/2006, 03h14   #1
key9
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut : cat | grep '^99\d' don't work

hi all

I have an file:
980<tab>980
981 981
982 982
983 983
984 984
985 985
986 986
987 987
988 988
989 989
990 990
991 991
992 992
993 993
994 994



I hope I can using "^99\d" to list 99x
or using "^992\t" to list "992"

but that don't work , why?

I have tried using [\d]... , no use.

thank you very much
key9


  Réponse avec citation
Vieux 02/12/2006, 04h48   #2
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: : cat | grep '^99\d' don't work

On 2006-12-02, key9 wrote:
> hi all
>
> I have an file:
> 980<tab>980
> 981 981
> 982 982
> 983 983
> 984 984
> 985 985
> 986 986
> 987 987
> 988 988
> 989 989
> 990 990
> 991 991
> 992 992
> 993 993
> 994 994
>
>
>
> I hope I can using "^99\d" to list 99x
> or using "^992\t" to list "992"
>
> but that don't work , why?
>
> I have tried using [\d]... , no use.


grep '^99[0-9]'

grep '^992'

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 02/12/2006, 08h33   #3
key9
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: : cat | grep '^99\d' don't work


> grep '^992'



this will also list 9920


take a look at this
format is

int<tab>string

70 xxx
74 xxx
75 xxx
750 anc
7500 bcd


I want show 7x line

whe I using '^7[0-9]'

it will also list 750 7500
but \t will not work : '^7[0-9]\t'





  Réponse avec citation
Vieux 02/12/2006, 09h18   #4
loic-dev@gmx.net
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: : cat | grep '^99\d' don't work

Hello,

> > grep '^992'

>
>
> this will also list 9920
>
>
> take a look at this
> format is
>
> int<tab>string
>
> 70 xxx
> 74 xxx
> 75 xxx
> 750 anc
> 7500 bcd
>
>
> I want show 7x line
>
> whe I using '^7[0-9]'
>
> it will also list 750 7500
> but \t will not work : '^7[0-9]\t'


Use "\s" to specify that there is a "space character" after your 7x
pattern:
grep '^7[0-9]\s'

HTH,
Loic.

  Réponse avec citation
Vieux 02/12/2006, 09h20   #5
Michal Nazarewicz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: : cat | grep '^99\d' don't work

"key9" <iamkey9@126.com> writes:

> take a look at this
> format is
>
> int<tab>string
>
> 70 xxx
> 74 xxx
> 75 xxx
> 750 anc
> 7500 bcd
>
> I want show 7x line


grep '^7[0-9][[:space:]]'

--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>---<jid:mina86*chrome.pl>--ooO--(_)--Ooo--
  Réponse avec citation
Vieux 02/12/2006, 09h58   #6
key9
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: : cat | grep '^99\d' don't work



> grep '^7[0-9]\s'


ok it works

but I wanna know why '^7[0-9]\t' not work?

Actually I generated this file using c++

std::cout << int << "\t" << string_ << std::endl;

and I using some hex editor exam the file , the "blank" is <tab> :-)

Dose \s means "human readable blank?"




  Réponse avec citation
Vieux 02/12/2006, 11h18   #7
key9
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: : cat | grep '^99\d' don't work

Hold on

it'still not work:
cat file > grep '^12\s'



using this code to generate file,we named the bin gener

#include <iostream>
#include <string>

using namespace c++

int main()
{
int la = 0;
int ua = 2000;
for(int i = la; i != ua; ++i){

cout << i << "\t" << i << endl;

}

}



gener > file
cat file > grep '^12\s'

I suppose it will display
12 12

but it display nothing



  Réponse avec citation
Vieux 02/12/2006, 11h19   #8
key9
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: : cat | grep '^99\d' don't work


> using namespace c++

sorry
using namespace std;


  Réponse avec citation
Vieux 02/12/2006, 11h25   #9
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: : cat | grep '^99\d' don't work

2006-12-2, 19:18(+08), key9:
> Hold on
>
> it'still not work:
> cat file > grep '^12\s'

[...]

That command will concatenate the content of the "file" and
"^12\s" files and store that in a file called "grep" in the
current directory.

grep '^12[[:blank:]]' < file

TAB=`printf '\t'`
grep "^12$TAB"

standard greps don't necessarily recognise any of those \s, \t,
\d...

awk recognises \t:

awk '/^12\t/'


--
Stéphane
  Réponse avec citation
Vieux 02/12/2006, 12h55   #10
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: : cat | grep '^99\d' don't work

key9 wrote:
>>grep '^992'

>
> this will also list 9920
>
> take a look at this
> format is
>
> int<tab>string
>
> 70 xxx
> 74 xxx
> 75 xxx
> 750 anc
> 7500 bcd
>
> I want show 7x line
>
> whe I using '^7[0-9]'
>
> it will also list 750 7500
> but \t will not work : '^7[0-9]\t'


Try any of...

grep '^7[0-9]\>'

grep -w '^7[0-9]'

grep '^7[0-9][ ]' # there's a space and a tab inside the []


Janis
  Réponse avec citation
Vieux 02/12/2006, 22h44   #11
loic-dev@gmx.net
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: : cat | grep '^99\d' don't work

Hi,

> Hold on
>
> it'still not work:
> cat file > grep '^12\s'


Of course, it doesn't work! Your last command should read:
$ cat file | grep '^12\s'

or even better:
$ grep '^12\s' file

the \s means "white space" which expands to something like:
[ \f\n\r\t\v]

Cheers,
Loic.

  Réponse avec citation
Vieux 03/12/2006, 00h28   #12
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: : cat | grep '^99\d' don't work

2006-12-2, 14:44(-08), loic-dev@gmx.net:
> Hi,
>
>> Hold on
>>
>> it'still not work:
>> cat file > grep '^12\s'

>
> Of course, it doesn't work! Your last command should read:
> $ cat file | grep '^12\s'
>
> or even better:
> $ grep '^12\s' file
>
> the \s means "white space" which expands to something like:
> [ \f\n\r\t\v]

[...]

In which version of grep is \s such a thing? Even GNU grep
doesn't seem to recognise \s.

\s is a blank (that is [ \t]) in perl (and perl compatible
regular expressions) and vim, that I know of.

GNU grep can be compile with PCRE support in which case you can
do: grep -P '^12\s' (still for [ \t]).

You could do:

perl -lne 'print if /^12\s/'

standard greps have [[:blank:]] for blank ([ \t]) and
[[:space:]] for space ([ \f\n\r\t\v]).

--
Stéphane
  Réponse avec citation
Vieux 03/12/2006, 00h55   #13
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: : cat | grep '^99\d' don't work

2006-12-3, 00:28(+00), Stephane CHAZELAS:
> 2006-12-2, 14:44(-08), loic-dev@gmx.net:
>> Hi,
>>
>>> Hold on
>>>
>>> it'still not work:
>>> cat file > grep '^12\s'

>>
>> Of course, it doesn't work! Your last command should read:
>> $ cat file | grep '^12\s'
>>
>> or even better:
>> $ grep '^12\s' file
>>
>> the \s means "white space" which expands to something like:
>> [ \f\n\r\t\v]

> [...]
>
> In which version of grep is \s such a thing? Even GNU grep
> doesn't seem to recognise \s.
>
> \s is a blank (that is [ \t]) in perl (and perl compatible
> regular expressions) and vim, that I know of.

[...]

My bad, \s is space ([ \f\n\r\t\v]) in perl/pcre and tcl (in
newer versions, inspired from perl), and blank ([ \t]) in vim.

>
> GNU grep can be compile with PCRE support in which case you can
> do: grep -P '^12\s' (still for [ \t]).


Would be [ \f\n\r\t\v] then.


--
Stéphane
  Réponse avec citation
Vieux 03/12/2006, 01h46   #14
John W. Krahn
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: : cat | grep '^99\d' don't work

Stephane CHAZELAS wrote:
> 2006-12-3, 00:28(+00), Stephane CHAZELAS:
>>2006-12-2, 14:44(-08), loic-dev@gmx.net:
>>
>>In which version of grep is \s such a thing? Even GNU grep
>>doesn't seem to recognise \s.
>>
>>\s is a blank (that is [ \t]) in perl (and perl compatible
>>regular expressions) and vim, that I know of.

> [...]
>
> My bad, \s is space ([ \f\n\r\t\v]) in perl/pcre and tcl (in
> newer versions, inspired from perl), and blank ([ \t]) in vim.


Perl doesn't have a "\v" character so \s is [ \f\n\r\t]. If you want the
vertical tab included then use [[:space:]].


John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h32.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,18335 seconds with 22 queries