Re: writing cron job to print query results
From: John-Paul Stewart (jpstewart_at_sympatico.ca)
Date: 07/11/03
- Next message: John Hasler: "Re: "Bugbear" virus in Linux?"
- Previous message: Jean-David Beyer: "Re: "Bugbear" virus in Linux?"
- In reply to: Robin: "Re: writing cron job to print query results"
- Next in thread: Robin: "Re: writing cron job to print query results"
- Reply: Robin: "Re: writing cron job to print query results"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 11 Jul 2003 14:38:52 -0400
Robin wrote:
>
> Bill Marcum <bmarcum@iglou.com> wrote in message news:<rrg1u-ldn.ln1@don.localnet>...
> > On 10 Jul 2003 16:18:35 -0700, Robin
> > <robin@witkopstaub.com> wrote:
> > > I want to search a text file for a condition and then if the condition
> > > exists print a line from above the condition. Sample of my text file
> > > is below
> > >
> > > user = sample {
> > > default service = permit
> > > login = cleartext "password"
> > > chap = cleartext "password"
> > > service = ppp protocol = ip {
> > > default attribute = permit
> > > }
> > > }
> > >
> > > I want to search for the login line, and if it exists print out the
> > > user = name from above. Is this possible to do with a grep and if
> > > statement in a cron job?
> >
> > grep -B 2 login < filename | head -1
> > assuming that "user = " is always two lines above "login".
>
> Thanks! The above command does work but I need it to search the entire
> file for any instance of the above condition. The listed command only
> shows my first user account found. The section above is duplicated
> about 100's of times and only a few have the login line in them. How
> do I make it start at the top of the file and search all the way
> through listing all users it finds with the login line?
grep always searches the entire file. The "-B 2" option is then
printing the two preceeding lines for every occurence of the pattern.
The problem is arising with the pipe to 'head -1', which is taking just
the first line of the entire output set. As an example try just:
grep -B 2 login < filename
It should print out every occurence of "login" plus the two lines
leading up to each. If you're only interested in the "user =" bit of
that output, grep for that. For example:
grep -B 2 login < filename | grep user
will extract the lines containing "user" from the output of my previous
example.
- Next message: John Hasler: "Re: "Bugbear" virus in Linux?"
- Previous message: Jean-David Beyer: "Re: "Bugbear" virus in Linux?"
- In reply to: Robin: "Re: writing cron job to print query results"
- Next in thread: Robin: "Re: writing cron job to print query results"
- Reply: Robin: "Re: writing cron job to print query results"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|