LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-05-2019, 10:27 AM   #1
dr.x
Member
 
Registered: Jan 2013
Posts: 231

Rep: Reputation: Disabled
tail -f helping


tail -f /var/log/messages/*-sockd.log | grep --line-buffered google | awk '{print $1,$6,$12,$17}'

05/Oct/2019:17:18:57 23.60.15.126 jan 515607
05/Oct/2019:17:18:57 2.147.234.142 minh 3342
05/Oct/2019:17:18:57 2.147.235.85 minh 442
05/Oct/2019:17:18:57 2.147.11.102 minh 333

but i want to count the last variable ,
i tried
tail -f /var/log/messages/*-sockd.log | grep --line-buffered google | awk '{print $1,$6,$12,$17}' | wc -m $17

but it fail , how can i count the digits in the output of the $17 variable ?

Thanks
 
Old 10-05-2019, 12:03 PM   #2
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,137
Blog Entries: 6

Rep: Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826
Code:
list=(
'05/Oct/2019:17:18:57 23.60.15.126 jan 515607'
'05/Oct/2019:17:18:57 2.147.234.142 minh 3342'
'05/Oct/2019:17:18:57 2.147.235.85 minh 442'
'05/Oct/2019:17:18:57 2.147.11.102 minh 333'
)

for i in "${list[@]}"; do
    echo "${#i}"
done

44
44
42
42
 
Old 10-05-2019, 12:14 PM   #3
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,137
Blog Entries: 6

Rep: Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826
Code:
strng='05/Oct/2019:17:18:57 2.147.11.102 minh 333'

wc <<< "$strng"
1  4 43
#1 line, 4 words 43 chars.

echo "${strng//[!0-9]/}"
#Just the intergers

echo "${strng//[!a-z]/}"
#Just the chars
That last one missed the capital O in Oct. I'll let you do that one.
 
Old 10-05-2019, 12:19 PM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,840

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
$17 exists only inside the awk script (which is now a single print command).
If you want to count you need to do it inside the awk script.
Actually grep is superfluous, you can do something like:
Code:
awk '/google/ { print $1,$6,$12,$17 }' /var/log/.....
and also you can make some other calculations instead of print.
But tail -f will be never finished, so your calculation will never be ready.
 
Old 10-05-2019, 12:19 PM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
I guess you could count the decimal places.

Code:
... | awk '/somepattern/{s=$17;d=0;while(s){s=int(s/10);d++};print $1,$6,$12,$17,d;}'
sub() could work that way, instead of int().
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
tail the output of tail -n 1 raj k yadav Linux - Newbie 5 02-06-2010 11:26 PM
How to make newer "tail" behave like older "tail" rylan76 Linux - Software 4 12-07-2007 04:27 AM
microsft helping US to spy? qanopus General 20 07-03-2003 11:46 AM
Thanks for helping me write FreeDoc lea Linux - General 1 11-15-2002 09:15 AM
Thanks for helping me writing FreeDoc lea Programming 0 11-15-2002 08:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration