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 > grep 2 words
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

grep 2 words

Réponse
 
LinkBack Outils de la discussion
Vieux 19/03/2008, 11h13   #1
Patrick
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut grep 2 words

hi everyone, on solaris 10 without gnu shell, how can i do to grep 2
word. Or 1 or 2?
for example i'd like to grep all lines with Feb or Mar in this file:
Fri Feb 29 12:00:00 2008:
Fri Feb 29 12:30:00 2008:
Fri Feb 29 13:00:01 2008:
Fri Feb 29 13:30:00 2008:
Sat Mar 1 04:00:00 2008:
Sat Mar 1 04:30:00 2008:
Sat Mar 1 05:00:00 2008:
Sat Mar 1 05:30:00 2008:
Sat Mar 1 06:00:00 2008:

thx
  Réponse avec citation
Vieux 19/03/2008, 11h23   #2
Patrick
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: grep 2 words

thank you very much!!

pk ha scritto:

> Patrick wrote:
>
> > hi everyone, on solaris 10 without gnu shell, how can i do to grep 2
> > word. Or 1 or 2?
> > for example i'd like to grep all lines with Feb or Mar in this file:
> > Fri Feb 29 12:00:00 2008:
> > Fri Feb 29 12:30:00 2008:
> > Fri Feb 29 13:00:01 2008:
> > Fri Feb 29 13:30:00 2008:
> > Sat Mar 1 04:00:00 2008:
> > Sat Mar 1 04:30:00 2008:
> > Sat Mar 1 05:00:00 2008:
> > Sat Mar 1 05:30:00 2008:
> > Sat Mar 1 06:00:00 2008:

>
> egrep 'Feb|Mar' file.txt
>
> or
>
> awk '/Feb/ || /Mar/' file.txt
>
> --
> All the commands are tested with bash and GNU tools, so they may use
> nonstandard features. I try to mention when something is nonstandard (if
> I'm aware of that), but I may miss something. Corrections are welcome.

  Réponse avec citation
Vieux 19/03/2008, 11h38   #3
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: grep 2 words

Patrick wrote:

> hi everyone, on solaris 10 without gnu shell, how can i do to grep 2
> word. Or 1 or 2?
> for example i'd like to grep all lines with Feb or Mar in this file:
> Fri Feb 29 12:00:00 2008:
> Fri Feb 29 12:30:00 2008:
> Fri Feb 29 13:00:01 2008:
> Fri Feb 29 13:30:00 2008:
> Sat Mar 1 04:00:00 2008:
> Sat Mar 1 04:30:00 2008:
> Sat Mar 1 05:00:00 2008:
> Sat Mar 1 05:30:00 2008:
> Sat Mar 1 06:00:00 2008:


egrep 'Feb|Mar' file.txt

or

awk '/Feb/ || /Mar/' file.txt

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
  Réponse avec citation
Vieux 19/03/2008, 11h42   #4
Luuk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: grep 2 words

pk schreef:
> Patrick wrote:
>
>> hi everyone, on solaris 10 without gnu shell, how can i do to grep 2
>> word. Or 1 or 2?
>> for example i'd like to grep all lines with Feb or Mar in this file:
>> Fri Feb 29 12:00:00 2008:
>> Fri Feb 29 12:30:00 2008:
>> Fri Feb 29 13:00:01 2008:
>> Fri Feb 29 13:30:00 2008:
>> Sat Mar 1 04:00:00 2008:
>> Sat Mar 1 04:30:00 2008:
>> Sat Mar 1 05:00:00 2008:
>> Sat Mar 1 05:30:00 2008:
>> Sat Mar 1 06:00:00 2008:

>
> egrep 'Feb|Mar' file.txt
>
> or
>
> awk '/Feb/ || /Mar/' file.txt
>


awk '/Feb|Mar/' file.txt

also seems to work...

--
Luuk
  Réponse avec citation
Vieux 19/03/2008, 12h05   #5
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: grep 2 words

Luuk wrote:

>> awk '/Feb/ || /Mar/' file.txt
>>

>
> awk '/Feb|Mar/' file.txt
>
> also seems to work...


Ah yes, of course. Thanks!

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
  Réponse avec citation
Vieux 19/03/2008, 22h37   #6
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: grep 2 words

On 2008-03-19, Patrick wrote:
> hi everyone, on solaris 10 without gnu shell, how can i do to grep 2
> word. Or 1 or 2?
> for example i'd like to grep all lines with Feb or Mar in this file:
> Fri Feb 29 12:00:00 2008:
> Fri Feb 29 12:30:00 2008:
> Fri Feb 29 13:00:01 2008:
> Fri Feb 29 13:30:00 2008:
> Sat Mar 1 04:00:00 2008:
> Sat Mar 1 04:30:00 2008:
> Sat Mar 1 05:00:00 2008:
> Sat Mar 1 05:30:00 2008:
> Sat Mar 1 06:00:00 2008:


grep -e Feb -e Mar FILE

--
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
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 08h24.


É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,20641 seconds with 14 queries