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

find expression in a file

Réponse
 
LinkBack Outils de la discussion
Vieux 17/07/2007, 19h32   #1
saam
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut find expression in a file

Guys,

I want to browse thru a file for a particular keyword..

ex: I want to go to all the places i.e where the keyword "temp" is
used in a file <abc.log>

Thanks

  Réponse avec citation
Vieux 17/07/2007, 21h04   #2
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find expression in a file

On Tue, 17 Jul 2007 11:32:23 -0700, saam
<shaiksameer@gmail.com> wrote:
>
>
> Guys,
>
> I want to browse thru a file for a particular keyword..
>
> ex: I want to go to all the places i.e where the keyword "temp" is
> used in a file <abc.log>
>
> Thanks
>

grep temp abc.log


--
People in general do not willingly read if they have anything else to
amuse them.
-- S. Johnson
  Réponse avec citation
Vieux 18/07/2007, 06h02   #3
Barry Margolin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find expression in a file

In article <j9hvm4-u0f.ln1@don.localnet>,
Bill Marcum <marcumbill@bellsouth.net> wrote:

> On Tue, 17 Jul 2007 11:32:23 -0700, saam
> <shaiksameer@gmail.com> wrote:
> >
> >
> > Guys,
> >
> > I want to browse thru a file for a particular keyword..
> >
> > ex: I want to go to all the places i.e where the keyword "temp" is
> > used in a file <abc.log>
> >
> > Thanks
> >

> grep temp abc.log


When he says "browse", I suspect he means interactively view the
sections of the file containing the keyword.

I suggest:

less abc.log
/temp

Then type "n" to get to each successive occurrence.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
  Réponse avec citation
Vieux 18/07/2007, 23h57   #4
rachit7@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find expression in a file

On Jul 17, 2:32 pm, saam <shaiksam...@gmail.com> wrote:
> Guys,
>
> I want to browse thru a file for a particular keyword..
>
> ex: I want to go to all the places i.e where the keyword "temp" is
> used in a file <abc.log>
>
> Thanks


The easiest way would be to use grep

$grep temp abc.log

but if you want to substitute something for the word "temp" then sed
will come in handy. Lets say you want to substitute every occurrence
of the word "temp" with the word "newword" then following command will
.

$ sed 's/temp/newword/g' abc.log > newabc.log

Remember, sed by default does not changes the actual file until you
tell it to do so; hence newabc.log file is created here.

Hope it s.
R

  Réponse avec citation
Vieux 18/07/2007, 23h57   #5
rachit7@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find expression in a file

On Jul 17, 2:32 pm, saam <shaiksam...@gmail.com> wrote:
> Guys,
>
> I want to browse thru a file for a particular keyword..
>
> ex: I want to go to all the places i.e where the keyword "temp" is
> used in a file <abc.log>
>
> Thanks


The easiest way would be to use grep

$grep temp abc.log

but if you want to substitute something for the word "temp" then sed
will come in handy. Lets say you want to substitute every occurrence
of the word "temp" with the word "newword" then following command will
.

$ sed 's/temp/newword/g' abc.log > newabc.log

Remember, sed by default does not changes the actual file until you
tell it to do so; hence newabc.log file is created here.

Hope it s.
R

  Réponse avec citation
Vieux 19/07/2007, 01h08   #6
johngnub
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find expression in a file

On Jul 17, 11:32 am, saam <shaiksam...@gmail.com> wrote:
> Guys,
>
> I want to browse thru a file for a particular keyword..
>
> ex: I want to go to all the places i.e where the keyword "temp" is
> used in a file <abc.log>
>
> Thanks


Grep !!
General use of grep, grep pattern filename,
Like...
grep "temp" thefile.txt

To see the line number, if you want that,
grep -n "temp" thefile.

Alt uses, -i for any case.
pipe then grep
cat mylog.log |grep "fun"
# save the result, handy,
cat mylog.log | grep "fun" >vas.ist.da.txt
# will find Fun, FUN fUn fUN
cat mylog.log | grep -i "fun"

Some Egrep,
.. for any char
[] things in this set
* da, many.
^ start of line
$ end of the line
+ one or more of the thing to the left
Eg:
grep . mylog.log |egrep "^fun"
# match on afun bfun 1fun
grep . mylog.log |egrep ".fun"
# run fun
grep . mylog.log |egrep "[rf]un"
# 1fun 2fun 3fun , thus is a set, any of the items in the set.
grep . mylog.log | egrep "[123]fun"
# range of things in a set, 1fun 2fun 3fun 4fun 5fun
grep . mylog.log | egrep "[1-5]fun"
# handy, seek 0 to 9, 0fun 1fun or 00fun
grep . mylog | egrep "[0-9]+fun"
# my fav, seek 100, 111, 125, 199,
grep . mylog.log | egrep "[1-9][0-9][0-9]"

Just 2 cents, JB

  Réponse avec citation
Vieux 19/07/2007, 01h08   #7
johngnub
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find expression in a file

On Jul 17, 11:32 am, saam <shaiksam...@gmail.com> wrote:
> Guys,
>
> I want to browse thru a file for a particular keyword..
>
> ex: I want to go to all the places i.e where the keyword "temp" is
> used in a file <abc.log>
>
> Thanks


Grep !!
General use of grep, grep pattern filename,
Like...
grep "temp" thefile.txt

To see the line number, if you want that,
grep -n "temp" thefile.

Alt uses, -i for any case.
pipe then grep
cat mylog.log |grep "fun"
# save the result, handy,
cat mylog.log | grep "fun" >vas.ist.da.txt
# will find Fun, FUN fUn fUN
cat mylog.log | grep -i "fun"

Some Egrep,
.. for any char
[] things in this set
* da, many.
^ start of line
$ end of the line
+ one or more of the thing to the left
Eg:
grep . mylog.log |egrep "^fun"
# match on afun bfun 1fun
grep . mylog.log |egrep ".fun"
# run fun
grep . mylog.log |egrep "[rf]un"
# 1fun 2fun 3fun , thus is a set, any of the items in the set.
grep . mylog.log | egrep "[123]fun"
# range of things in a set, 1fun 2fun 3fun 4fun 5fun
grep . mylog.log | egrep "[1-5]fun"
# handy, seek 0 to 9, 0fun 1fun or 00fun
grep . mylog | egrep "[0-9]+fun"
# my fav, seek 100, 111, 125, 199,
grep . mylog.log | egrep "[1-9][0-9][0-9]"

Just 2 cents, JB

  Réponse avec citation
Vieux 19/07/2007, 07h24   #8
johngnub
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find expression in a file

On Jul 17, 1:04 pm, Bill Marcum <marcumb...@bellsouth.net> wrote:
> On Tue, 17 Jul 2007 11:32:23 -0700, saam <shaiksam...@gmail.com> wrote:
>
> > Guys,

>
> > I want to browse thru a file for a particular keyword..

>
> > ex: I want to go to all the places i.e where the keyword "temp" is
> > used in a file <abc.log>

>
> > Thanks

>
> grep temp abc.log
>
> --
> People in general do not willingly read if they have anything else to
> amuse them.
> -- S. Johnson


I did a reply to this early today, hmmm, issues,,,,,,,,,, JB

  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 05h28.


É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,16264 seconds with 16 queries