You are not logged in.
To start off, I have this command:
awk '{print "Pacman performed an activty "$1" times on "$2}' <(awk '{print $1}' /var/log/pacman.log | uniq -c | tr -d '[]')
Here is some sample output from that command
Pacman performed an activty 111 times on 2014-11-14
Pacman performed an activty 31 times on 2014-11-15
Pacman performed an activty 12 times on 2014-11-16
Pacman performed an activty 21 times on 2014-11-17
Pacman performed an activty 21 times on 2014-11-18
Pacman performed an activty 20 times on 2014-11-20
Pacman performed an activty 83 times on 2014-11-22
Pacman performed an activty 17 times on 2014-11-23
Pacman performed an activty 4 times on 2014-11-24
Pacman performed an activty 9 times on 2014-11-25
Pacman performed an activty 39 times on 2014-11-27
Sample content of pacman.log
[2014-11-27 09:05] [PACMAN] synchronizing package lists
[2014-11-27 09:24] [PACMAN] Running 'pacman -Syu'
[2014-11-27 09:24] [PACMAN] synchronizing package lists
[2014-11-27 09:25] [PACMAN] starting full system upgrade
[2014-11-27 09:26] [PACMAN] upgraded autojump (21.7.1-1 -> 21.7.1-2)
[2014-11-27 09:26] [PACMAN] upgraded ca-certificates-mozilla (3.17.2-2 -> 3.17.2-3)
[2014-11-27 09:26] [PACMAN] upgraded nss (3.17.2-2 -> 3.17.2-3)
[2014-11-27 09:26] [PACMAN] upgraded flac (1.3.0-4 -> 1.3.0-5)
[2014-11-27 09:27] [PACMAN] upgraded chromium (39.0.2171.65-1 -> 39.0.2171.71-1)
Right now I want to show all the times for each specific date pacman does something. I would like my output to look like this
Pacman performed an activty 30 times on 2014-11-14
9:24
9:26
9:27
Pacman performedan activity 50 times on 2014-01-10
9:24
15:36
18:54
Just trying to learn awk and bash. I feel I can go somewhere pretty neat with the script. Basically I need to figure out how to print the cellss of the times for each specific date. I have the first part done. For the second part, I am completely lost Any help would be must appreciated.
Eventually, I would like it to show packages updated for that date etc. Right now I am just focused on the times. Any help would be must appreciated.
Last edited by quasifilmie (2014-11-30 07:14:49)
Offline
Just wanna further explain what I'm doing. I can get the times to output but it shows the date and amount of activities as duplicates.
awk '{print "Pacman did an activty "$1" times on "$2, "\nthe times are" ,$3}' <(awk '{print $1, $2}' /var/log/pacman.log | uniq -c | tr -d '[]')
Pacman did an activity 3 times on 2014-11-23
the times are 15:52
Pacman did an activity 4 times on 2014-11-24
the times are 16:24
Pacman did an activity 6 times on 2014-11-25
the times are 11:21
Pacman did an activity 3 times on 2014-11-25
the times are 11:23
Pacman did an activity 2 times on 2014-11-27
the times are 09:05
I'm wondering if I need an array and/or counter. Or am I over-complicating it?
Offline
This is pretty easy; since you are trying to learn something I'd suggest you have a look at http://www.tldp.org/LDP/abs/html/ and attempt to use variables, if-statements and while-loops; it should be pretty doable. In meta-code, I think you should aim for something like:
while read date time
do
if $date == $prev_date
times=($times $time)
else
echo $date - $times
done
Last edited by Spider.007 (2014-12-13 12:48:18)
Offline
The uniq and tr pipeline is not needed - and likely will make it harder to troubleshoot. Also recursive awk'ing is a bit odd. This can be done with a single invocation of awk. Check out the (g)awk manual to learn how (hint you'll likely want to use an associative array).
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline