grepping last entry on a single line
Hi All Im trying to figgure out how to grep a file and only produce the *last* line found. I want to cat /var/log/messages | grep remote this outouts all line which contain remote, I only want the last one I plant to display onscreen my remote ip when I connect to my isp. I looked into uniq but obiviously the datestamp makes eask entry unique any ideas on to to use grep for my needs thanks rob -- God may be subtle, but He isn't plain mean. -- Albert Einstein 6:05am up 3 days, 7:30, 4 users, load average: 1.00, 1.00, 1.00 __ _ / / (_)__ __ ____ __ / /__/ / _ \/ // /\ \ / /____/_/_//_/\_,_//_\_\
Hi, On Thu, Mar 22 2001 at 06:48 -0500, dizzy73 wrote:
Im trying to figgure out how to grep a file and only produce the *last* line found. I want to cat /var/log/messages | grep remote this outouts all line which contain remote, I only want the last one I plant to display onscreen my remote ip when I connect to my isp.
Try `grep remote /var/log/messages | tail -1'. Ciao, Stefan -- Stefan Troeger o _ _ _ stefan@troeger.st __o __o /\_ _ \\o (_)\__/o (_) _`\<, _`\<, _>(_) (_)/<_ \_| \ _|/' \/ (_)/(_) (_)/(_) (_) (_) (_) (_)' _\o_
Today, Stefan Troeger smoke something and in the trip wrote...
Hi,
On Thu, Mar 22 2001 at 06:48 -0500, dizzy73 wrote:
Im trying to figgure out how to grep a file and only produce the *last* line found. I want to cat /var/log/messages | grep remote this outouts all line which contain remote, I only want the last one I plant to display onscreen my remote ip when I connect to my isp.
Try `grep remote /var/log/messages | tail -1'.
maybe use /etc/ppp/ip-up to print its argument is less resource-intensive than searching through /var/log/messages :) obviously, only if you connect via ppp :) but maybe ifconfig "you_net_interface" | grep | sed do the trick :) Regards, Adilson
Hi, On Thu, Mar 22 2001 at 09:15 -0300, Adilson Guilherme Vasconcelos Ribeiro wrote:
Today, Stefan Troeger smoke something and in the trip wrote...
Try `grep remote /var/log/messages | tail -1'.
maybe use /etc/ppp/ip-up to print its argument is less resource-intensive than searching through /var/log/messages :)
obviously, only if you connect via ppp :)
but maybe ifconfig "you_net_interface" | grep | sed do the trick
Yep, something like this should do the trick (for ppp): ifconfig |grep -A1 "^ppp" |grep "inet addr" |cut -d ':' -f 2 |cut -d ' ' -f 1 Ciao, Stefan -- Stefan Troeger o _ _ _ stefan@troeger.st __o __o /\_ _ \\o (_)\__/o (_) _`\<, _`\<, _>(_) (_)/<_ \_| \ _|/' \/ (_)/(_) (_)/(_) (_) (_) (_) (_)' _\o_
On Thu, 22 Mar 2001 06:48:46 -0500 (EST), dizzy73 said: | Hi All | Im trying to figgure out how to grep a file and only produce the | *last* line found. man tail -- ---------------------------------------------------- Koos Pol T: +31 20 3116122 Systems Administrator F: +31 20 3116200 Compuware Europe B.V. E: koos_pol@nl.compuware.com Amsterdam PGP public key available
yes of course tail... but I only want one line with the word *remote* I dont want the entire portion of tail Ok so you youre suggesting cat /var/log/messages | grep remote | tail -n 1 > myip ok Ill check that many thanks rob Koos Pol wrote:
On Thu, 22 Mar 2001 06:48:46 -0500 (EST), dizzy73 said:
| Hi All | Im trying to figgure out how to grep a file and only produce the | *last* line found.
man tail
-- ---------------------------------------------------- Koos Pol T: +31 20 3116122 Systems Administrator F: +31 20 3116200 Compuware Europe B.V. E: koos_pol@nl.compuware.com Amsterdam PGP public key available
-- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/support/faq
On 22 Mar, dizzy73 wrote:
Hi All Im trying to figgure out how to grep a file and only produce the *last* line found. I want to cat /var/log/messages | grep remote this outouts all line which contain remote, I only want the last one I plant to display onscreen my remote ip when I connect to my isp.
I looked into uniq but obiviously the datestamp makes eask entry unique
any ideas on to to use grep for my needs
thanks rob
If you need the IP address, save it off from /etc/ppp/ip-up.local, and bypass grep altogether. For example, your /etc/ppp/ip-up.local would contain the line: echo $5 > /var/run/$1.ip This would create (or overwrite) a file with your remote IP address. With dial-up, you'd get /var/run/ppp0.ip. "$5" is the remote IP address. There's a local IP address in "$4". I assume you need remote ($5). "$1" is the interface: "ppp0" for most dial-ups. Now any scripts can read the IP address from /var/run/ppp0.ip. No need for messy grep commands on your log files. For security reasons, you may want to change the permissions on /var/run/ppp0.ip. Keep unauthorized users from reading it. But I'm just being paranoid... echo $5 > /var/run/$1.ip chmod u=rw,g=r,o= /var/run/$1.ip -- Robert Wohlfarth rjwohlfar@bigfoot.com "Is not life more important than food, and the body more important than clothes?" -- Matthew 6:25b
participants (5)
-
Adilson Guilherme Vasconcelos Ribeiro
-
dizzy73
-
Koos Pol
-
rjwohlfar@bigfoot.com
-
Stefan Troeger