You are not logged in.
Pages: 1
Topic closed
(The following isn't really an issue with pacman itself but rather with shell scripting, in particular the sed command.)
I'm trying to get a list of installed packages sorted by install date.
I got this far:
pacman -Qi | grep -P "^(Name|Install Date)" | sed -r ":a;N;s/Name\s+: (.*)\nInstall Date\s+: (.*)/`date +%F_%T --date='\\\2'`\t\1/" | sort | head(I use the 'head' command only because I'm debugging it)
I get this result:
date: invalid date `\\\\2'
a52dec
aalib
acl
akonadi
alsa-lib
alsa-oss
alsa-utils
amarok
apr
apr-util
And I want something like this:
2009-11-07 22:20:04 acl
2009-11-07 22:20:04 attr
2009-11-07 22:20:04 bash
2009-11-07 22:20:04 ncurses
2009-11-07 22:20:04 readline
2009-11-07 22:20:04 zlib
2009-11-07 22:20:05 coreutils
2009-11-07 22:20:05 cpio
2009-11-07 22:20:05 cracklib
2009-11-07 22:20:05 db
Can someone help me figure out how to fix this command?
Last edited by zZyXx (2009-12-03 23:35:57)
Offline
With yaourt you can do: "yaourt -Q --date"
Offline
date will be called before sed even. You want to run date from within the command, but sed can't do that, you would need something like awk. Or you can output the result like above (without date) and interpret it with bash. E.g. a "while read" loop:
IFS=$'\t'
pacman -Qi | grep -P "^(Name|Install Date)" | sed -r ":a;N;s/Name\s+: (.*)\nInstall Date\s+: (.*)/\2\t\1/" | while read pkg_date pkg_name; do echo -e $(date +%F\ %T --date="$pkg_date") '\t' $pkg_name; done | sort | headYou can simplify that grep/sed with: sed -n '/^Name/{s/.* : //;h};/^Install Date/{s/.* : //;G;s/\n/\t/p}'
Offline
You might have an easier time of it parsing pacman.log instead of pacman's output.
Offline
great input! thanks everyone.
Offline
I would have to say this would be way easier as a script (as mentioned by Procyon previously) but you wanted sed and you got it. I just slapped this together so go easy (I'm learning this stuff and I used this as a good training exercise). Also you might have to test to see if I have the right month abbreviations and if they work. All I could test was Nov and Dec (as I just reloaded Arch) but the other months should work as long as I got the right abbreviations in there. If not just fix them to what they really are. It seems to be outputting what you wanted on my machine. No other commands required just pacman and sed.
Example:
2009-11-28 05:18:34 abs
2009-11-25 11:09:55 acl
2009-11-27 17:35:54 advancecomp
2009-12-04 15:31:17 alsa-lib
2009-12-04 15:33:13 alsa-utils
2009-11-28 05:26:07 apr
2009-11-28 05:27:05 apr-util
2009-11-25 19:48:12 arno-iptables-firewall
2009-11-28 05:29:35 aspell
2009-11-28 05:29:55 aspell-en
2009-11-29 07:25:41 atk
2009-11-28 05:31:53 atool
2009-11-25 11:09:55 attr
2009-12-03 17:52:47 autoconf
etc.
Here you go:
pacman -Qi | sed '/^Name/{ s/ *//; s/^.* //; H;N;d}; /^URL/,/^Build Date/d; /^Install Reason/,/^Description/d; /^ */d;x; s/^.*: ... //; s/Jan/01/; s/Feb/02/; s/Mar/03/; s/Apr/04/; s/May/05/; s/Jun/06/; s/Jul/07/; s/Aug/08/; s/Sep/09/; s/Oct/10/; s/Nov/11/; s/Dec/12/; / [1-9]\{1\} /{ s/[[:digit:]]\{1\}/0&/3 }; s/\(^[[:digit:]][[:digit:]]\) \([[:digit:]][[:digit:]]\) \(.*\) \(....\)/\4-\1-\2 \3/' | sed ' /^[[:alnum:]].*$/ N; s/\n/ /; s/\(^[[:graph:]]*\) \(.*$\)/\2 \1/'Hope it works for you! ![]()
Think I'll go do something simple now like write an all assembly code version of Windows 7 or something. ![]()
P.S. If you want it to look exactly like what you have above (I.E. no blank spaces between lines) then use this instead:
pacman -Qi | sed '/^Name/{ s/ *//; s/^.* //; H;N;d}; /^URL/,/^Build Date/d; /^Install Reason/,/^Description/d; /^ */d;x; s/^.*: ... //; s/Jan/01/; s/Feb/02/; s/Mar/03/; s/Apr/04/; s/May/05/; s/Jun/06/; s/Jul/07/; s/Aug/08/; s/Sep/09/; s/Oct/10/; s/Nov/11/; s/Dec/12/; / [1-9]\{1\} /{ s/[[:digit:]]\{1\}/0&/3 }; s/\(^[[:digit:]][[:digit:]]\) \([[:digit:]][[:digit:]]\) \(.*\) \(....\)/\4-\1-\2 \3/' | sed ' /^[[:alnum:]].*$/ N; s/\n/ /; s/\(^[[:graph:]]*\) \(.*$\)/\2 \1/; /^$/d'Last edited by harryNID (2009-12-05 01:55:09)
In solving a problem of this sort, the grand thing is to be able to reason backward. That is a very useful accomplishment, and a very easy one, but people do not practice it much. In the everyday affairs of life it is more useful to reason forward, and so the other comes to be neglected. There are fifty who can reason synthetically for one who can reason analytically. --Sherlock Holmes
Offline
Hello
How to adaptate this feature for cyrillic use?
I tried:
pacman -Qi | sed '/^Название/{ s/ *//; s/^.* //; H;N;d}; /^URL/,/^Дата сборки/d; /^Причина установки/,/^Описание/d; /^ */d;x; s/^.*: ... //; s/янв/01/; s/фев/02/; s/мар/03/; s/апр/04/; s/май/05/; s/июн/06/; s/июл/07/; s/авг/08/; s/сен/09/; s/окт/10/; s/нов/11/; s/дек/12/; / [1-9]\{1\} /{ s/[[:digit:]]\{1\}/0&/3 }; s/\(^[[:digit:]][[:digit:]]\) \([[:digit:]][[:digit:]]\) \(.*\) \(....\)/\4-\1-\2 \3/' | sed ' /^[[:alnum:]].*$/ N; s/\n/ /; s/\(^[[:graph:]]*\) \(.*$\)/\2 \1/; /^$/d'My output on pacman -Qi:
Название : zvbi
Версия : 0.2.35-1
Описание : VBI capture and decoding library
Архитектура : x86_64
URL : http://zapping.sourceforge.net/cgi-bin/view/ZVBI/WebHome
Лицензии : GPL
Группы : Нет
Предоставляет : Нет
Зависит от : libpng libx11
Дополнительно : Нет
Требуется пакетами : vlc
Дополнительно для : Нет
Конфликтует с : Нет
Заменяет : Нет
Установленный размер: 1303,00 KiB
Сборщик : Eric Belanger <eric@archlinux.org>
Дата сборки : Чт 08 янв 2015 20:39:31
Дата установки : Сб 12 сен 2015 04:29:47
Причина установки : Установлен как зависимость другого пакета
Установочный скрипт : No
Проверен : ПодписьOutput after script execution:
Архитектура : x86_64 xvidcore
уста11ки : Вт 07 07 2015 18:27:13 xz Дата
: x86_64 Дата уста11ки : Вт 07 07 2015 18:07:43 Архитектура
Архитектура : x86_64 zeromq
уста11ки : Сб 29 08 2015 10:57:56 zip Дата
: x86_64 Дата уста11ки : Пт 18 09 2015 10:13:05 Архитектура
Архитектура : x86_64 zlib
уста11ки : Вт 07 07 2015 18:07:39 zvbi Дата
Архитектура : x86_64Offline
There are only package names and ISO formatted dates in the desired output, so the locale doesn't matter. You can prepend LANG=C and use the original regexps.
And you should probably have started a new thread, but now that this has been bumped, let me mention expac (didn't exist in 2009) for all your package database extraction tasks. In this case
$ expac --timefmt='%F %T' '%l %n' | sort -nshould do it.
Last edited by Raynman (2015-09-20 09:42:00)
Offline
As Raynman says, next time you have a question that is partially addressed by an ancient topic, please open a new topic and link back to the old one.
https://wiki.archlinux.org/index.php/Fo … bumping.22
Closing.
Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD
Making lemonade from lemons since 2015.
Offline
Pages: 1
Topic closed