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 > Find a string with a specified number os lines
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Find a string with a specified number os lines

Réponse
 
LinkBack Outils de la discussion
Vieux 03/11/2006, 16h09   #1
apogeusistemas@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Find a string with a specified number os lines

How could I find a string with a specified number os lines ?

Like this

$ cat file

apple
banana
orange
eggs
strawberry

$ grep -L 3 file orange

banana
orange
eggs

Obviously the -L parameter doesn't exist in grep.


Regards

  Réponse avec citation
Vieux 03/11/2006, 16h18   #2
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Find a string with a specified number os lines

2006-11-3, 08:09(-08), apogeusistemas@gmail.com:
> How could I find a string with a specified number os lines ?
>
> Like this
>
> $ cat file
>
> apple
> banana
> orange
> eggs
> strawberry
>
> $ grep -L 3 file orange
>
> banana
> orange
> eggs
>
> Obviously the -L parameter doesn't exist in grep.

[...]

awk 'NR == 3 && /orange/' < file

sed '3!d;/orange/!d' < file

--
Stéphane
  Réponse avec citation
Vieux 03/11/2006, 17h43   #3
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Find a string with a specified number os lines

Stephane CHAZELAS wrote:
> 2006-11-3, 08:09(-08), apogeusistemas@gmail.com:
>
>>How could I find a string with a specified number os lines ?
>>
>>Like this
>>
>>$ cat file
>>
>>apple
>>banana
>>orange
>>eggs
>>strawberry
>>
>>$ grep -L 3 file orange
>>
>>banana
>>orange
>>eggs
>>
>>Obviously the -L parameter doesn't exist in grep.

>
> [...]
>
> awk 'NR == 3 && /orange/' < file
>
> sed '3!d;/orange/!d' < file
>


I THINK what the OP wanted was to print 3 lines of context around a
pattern, not the line that pattern is on if it's on a specific line number.

For the OP: get GNU grep and check the man page, what you seem to want
is already present.

Ed.
  Réponse avec citation
Vieux 03/11/2006, 18h00   #4
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Find a string with a specified number os lines

2006-11-03, 11:43(-06), Ed Morton:
[...]
>>>$ grep -L 3 file orange
>>>
>>>banana
>>>orange
>>>eggs
>>>
>>>Obviously the -L parameter doesn't exist in grep.

>>
>> [...]
>>
>> awk 'NR == 3 && /orange/' < file
>>
>> sed '3!d;/orange/!d' < file
>>

>
> I THINK what the OP wanted was to print 3 lines of context around a
> pattern, not the line that pattern is on if it's on a specific line number.


Indeed. I should get back to bed asap...

> For the OP: get GNU grep and check the man page, what you seem to want
> is already present.

[...]

Yes, and search this group archives where the question is often
asked.

--
Stéphane
  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 22h18.


É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,29136 seconds with 12 queries