Skip to content

Instantly share code, notes, and snippets.

@RealYukiSan
Created August 8, 2024 03:04
Show Gist options
  • Save RealYukiSan/b26b85cc8e76d3132ae6080316428f1f to your computer and use it in GitHub Desktop.
Save RealYukiSan/b26b85cc8e76d3132ae6080316428f1f to your computer and use it in GitHub Desktop.
[ARCH LINUX PACMAN] print the sorted date and formatted output of pacman -Qei
#!/usr/bin/bash
pacman -Qei | grep --color=never -E '^(Name|Install Date)' | awk -F': ' '/^Name/ {name=$2} /^Install Date/ {print $2, name}' | awk '
BEGIN {
# Define month names for conversion
split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec", months, " ")
}
{
# Extract the date and time parts
if ($1 ~ /^Mon|Tue|Wed|Thu|Fri|Sat|Sun/) {
day = $2
month = $3
year = $4
time = $5
ampm = $6
timezone = $7
pkgname = $8
# Convert the month to a number
for (i = 1; i <= 12; i++) {
if (month == months[i]) {
month_num = (i < 10 ? "0" i : i)
break
}
}
# Convert the date to YYYY-MM-DD HH:MM:SS
print year "-" month_num "-" day " " time " " ampm, timezone, pkgname
}
}' | sort
@RealYukiSan
Copy link
Author

RealYukiSan commented Aug 8, 2024

You can also do the alternative: grep -E 'pacman -S [^ ]+|asexplicit' /var/log/pacman.log

this alternative address the initial date problem

@RealYukiSan
Copy link
Author

to find the duplicate: awk -F"'" '{print $2}' /var/log/pacman.log | grep --color=never -E 'pacman -S [^ ]+' | sort | uniq -d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment