第一种方法:

第一种方法:

我想提取特定日期内已安装的软件包,以便轻松删除它们。我可以使用以下命令将它们列在一行中:

 cat /var/log/dpkg.log | awk '/ installed / && /2020-11-23 14:/ {print $5}' | awk '{printf "%s ", gensub(/:.*/,"\\1", "g", $1); }'

libstartup-notification0-dev po-debconf libdebhelper-perl libwnck-common gir1.2-gtk-2.0 libwnck22 dwz libarchive-cpio-perl libsub-override-perl libxres-dev libgtk2.0-dev libsys-hostname-long-perl libfile-stripnondeterminism-perl gir1.2-wnck-1.0 libmail-sendmail-perl dh-strip-nondeterminism libwnck-dev dh-autoreconf debhelper man-db doc-base libc-bin libwnck-dev libwnck-3-dev dh-autoreconf debhelper dh-strip-nondeterminism dwz libgtk2.0-dev gir1.2-wnck-1.0 gir1.2-gtk-2.0 libarchive-cpio-perl libdebhelper-perl libfile-stripnondeterminism-perl libmail-sendmail-perl libwnck-3-dev libstartup-notification0-dev libsub-override-perl libsys-hostname-long-perl libwnck22 libwnck-common libxres-dev

但是,正如您所注意到的,一些已经安装的软件包也被列出,因为 apt 必须运行一些基本软件包来配置系统。

幸运的是,我可以通过以下方式区分这些包

cat /var/log/dpkg.log | awk '/ trigproc / && /2020-11-23 14:/ {print $4}' | awk '{printf "%s ", gensub(/:.*/,"\\1", "g", $1); }' 

man-db doc-base libc-bin libc-bin man-db doc-base

如何比较两行并通过 删除第一行中与第二行相同的包awk

编辑:格式/var/log/dpkg.log如下:

2020-11-23 14:43:30 startup archives unpack
2020-11-23 14:43:31 install dh-autoreconf:all <none> 19
2020-11-23 14:43:31 status half-installed dh-autoreconf:all 19
2020-11-23 14:43:32 status triggers-pending man-db:amd64 2.9.1-1
2020-11-23 14:43:32 status unpacked dh-autoreconf:all 19
2020-11-23 14:43:33 install libdebhelper-perl:all <none> 12.10ubuntu1
2020-11-23 14:43:33 status half-installed libdebhelper-perl:all 12.10ubuntu1
2020-11-23 14:43:33 status unpacked libdebhelper-perl:all 12.10ubuntu1
2020-11-23 14:43:34 install libsub-override-perl:all <none> 0.09-2
2020-11-23 14:43:34 status half-installed libsub-override-perl:all 0.09-2
2020-11-23 14:43:34 status unpacked libsub-override-perl:all 0.09-2
2020-11-23 14:43:34 install libfile-stripnondeterminism-perl:all <none> 1.7.0-1
2020-11-23 14:43:34 status half-installed libfile-stripnondeterminism-perl:all 1.7.0-1
2020-11-23 14:43:35 status unpacked libfile-stripnondeterminism-perl:all 1.7.0-1
2020-11-23 14:43:35 install dh-strip-nondeterminism:all <none> 1.7.0-1
2020-11-23 14:43:35 status half-installed dh-strip-nondeterminism:all 1.7.0-1
2020-11-23 14:43:36 status unpacked dh-strip-nondeterminism:all 1.7.0-1
2020-11-23 14:43:36 install dwz:amd64 <none> 0.13-5
2020-11-23 14:43:36 status half-installed dwz:amd64 0.13-5
2020-11-23 14:43:37 status unpacked dwz:amd64 0.13-5
2020-11-23 14:43:37 install po-debconf:all <none> 1.0.21
2020-11-23 14:43:37 status half-installed po-debconf:all 1.0.21
2020-11-23 14:43:37 status triggers-pending doc-base:all 0.10.9
2020-11-23 14:43:38 status unpacked po-debconf:all 1.0.21
2020-11-23 14:43:38 install debhelper:all <none> 12.10ubuntu1
2020-11-23 14:43:38 status half-installed debhelper:all 12.10ubuntu1
2020-11-23 14:43:39 status unpacked debhelper:all 12.10ubuntu1
2020-11-23 14:43:40 install gir1.2-gtk-2.0:amd64 <none> 2.24.32-4ubuntu4
2020-11-23 14:43:40 status half-installed gir1.2-gtk-2.0:amd64 2.24.32-4ubuntu4
2020-11-23 14:43:40 status unpacked gir1.2-gtk-2.0:amd64 2.24.32-4ubuntu4
2020-11-23 14:43:41 install libwnck-common:all <none> 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:41 status half-installed libwnck-common:all 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:41 status unpacked libwnck-common:all 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:42 install libwnck22:amd64 <none> 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:42 status triggers-pending libc-bin:amd64 2.31-0ubuntu9.1
2020-11-23 14:43:42 status half-installed libwnck22:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:43 status unpacked libwnck22:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:43 install gir1.2-wnck-1.0:amd64 <none> 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:43 status half-installed gir1.2-wnck-1.0:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:44 status unpacked gir1.2-wnck-1.0:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:44 install libarchive-cpio-perl:all <none> 0.10-1
2020-11-23 14:43:44 status half-installed libarchive-cpio-perl:all 0.10-1
2020-11-23 14:43:45 status unpacked libarchive-cpio-perl:all 0.10-1
2020-11-23 14:43:45 install libgtk2.0-dev:amd64 <none> 2.24.32-4ubuntu4
2020-11-23 14:43:45 status half-installed libgtk2.0-dev:amd64 2.24.32-4ubuntu4
2020-11-23 14:43:47 status unpacked libgtk2.0-dev:amd64 2.24.32-4ubuntu4
2020-11-23 14:43:48 install libsys-hostname-long-perl:all <none> 1.5-1
2020-11-23 14:43:48 status half-installed libsys-hostname-long-perl:all 1.5-1
2020-11-23 14:43:48 status unpacked libsys-hostname-long-perl:all 1.5-1
2020-11-23 14:43:49 install libmail-sendmail-perl:all <none> 0.80-1
2020-11-23 14:43:49 status half-installed libmail-sendmail-perl:all 0.80-1
2020-11-23 14:43:50 status unpacked libmail-sendmail-perl:all 0.80-1
2020-11-23 14:43:51 install libstartup-notification0-dev:amd64 <none> 0.12-6
2020-11-23 14:43:51 status half-installed libstartup-notification0-dev:amd64 0.12-6
2020-11-23 14:43:51 status unpacked libstartup-notification0-dev:amd64 0.12-6
2020-11-23 14:43:52 install libxres-dev:amd64 <none> 2:1.2.0-4
2020-11-23 14:43:52 status half-installed libxres-dev:amd64 2:1.2.0-4
2020-11-23 14:43:52 status unpacked libxres-dev:amd64 2:1.2.0-4
2020-11-23 14:43:53 install libwnck-dev:amd64 <none> 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:53 status half-installed libwnck-dev:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:53 status unpacked libwnck-dev:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:54 startup packages configure
2020-11-23 14:43:54 configure libstartup-notification0-dev:amd64 0.12-6 <none>
2020-11-23 14:43:54 status unpacked libstartup-notification0-dev:amd64 0.12-6
2020-11-23 14:43:54 status half-configured libstartup-notification0-dev:amd64 0.12-6
2020-11-23 14:43:54 status installed libstartup-notification0-dev:amd64 0.12-6
2020-11-23 14:43:54 configure po-debconf:all 1.0.21 <none>
2020-11-23 14:43:54 status unpacked po-debconf:all 1.0.21
2020-11-23 14:43:54 status half-configured po-debconf:all 1.0.21
2020-11-23 14:43:54 status installed po-debconf:all 1.0.21
2020-11-23 14:43:54 configure libdebhelper-perl:all 12.10ubuntu1 <none>
2020-11-23 14:43:54 status unpacked libdebhelper-perl:all 12.10ubuntu1
2020-11-23 14:43:54 status half-configured libdebhelper-perl:all 12.10ubuntu1
2020-11-23 14:43:54 status installed libdebhelper-perl:all 12.10ubuntu1
2020-11-23 14:43:54 configure libwnck-common:all 1:2.30.7-5.1ubuntu1 <none>
2020-11-23 14:43:54 status unpacked libwnck-common:all 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:55 status half-configured libwnck-common:all 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:55 status installed libwnck-common:all 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:55 configure gir1.2-gtk-2.0:amd64 2.24.32-4ubuntu4 <none>
2020-11-23 14:43:55 status unpacked gir1.2-gtk-2.0:amd64 2.24.32-4ubuntu4
2020-11-23 14:43:55 status half-configured gir1.2-gtk-2.0:amd64 2.24.32-4ubuntu4
2020-11-23 14:43:55 status installed gir1.2-gtk-2.0:amd64 2.24.32-4ubuntu4
2020-11-23 14:43:55 configure libwnck22:amd64 1:2.30.7-5.1ubuntu1 <none>
2020-11-23 14:43:55 status unpacked libwnck22:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:55 status half-configured libwnck22:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:55 status installed libwnck22:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:55 configure dwz:amd64 0.13-5 <none>
2020-11-23 14:43:55 status unpacked dwz:amd64 0.13-5
2020-11-23 14:43:55 status half-configured dwz:amd64 0.13-5
2020-11-23 14:43:55 status installed dwz:amd64 0.13-5
2020-11-23 14:43:55 configure libarchive-cpio-perl:all 0.10-1 <none>
2020-11-23 14:43:55 status unpacked libarchive-cpio-perl:all 0.10-1
2020-11-23 14:43:55 status half-configured libarchive-cpio-perl:all 0.10-1
2020-11-23 14:43:55 status installed libarchive-cpio-perl:all 0.10-1
2020-11-23 14:43:56 configure libsub-override-perl:all 0.09-2 <none>
2020-11-23 14:43:56 status unpacked libsub-override-perl:all 0.09-2
2020-11-23 14:43:56 status half-configured libsub-override-perl:all 0.09-2
2020-11-23 14:43:56 status installed libsub-override-perl:all 0.09-2
2020-11-23 14:43:56 configure libxres-dev:amd64 2:1.2.0-4 <none>
2020-11-23 14:43:56 status unpacked libxres-dev:amd64 2:1.2.0-4
2020-11-23 14:43:56 status half-configured libxres-dev:amd64 2:1.2.0-4
2020-11-23 14:43:56 status installed libxres-dev:amd64 2:1.2.0-4
2020-11-23 14:43:56 configure libgtk2.0-dev:amd64 2.24.32-4ubuntu4 <none>
2020-11-23 14:43:56 status unpacked libgtk2.0-dev:amd64 2.24.32-4ubuntu4
2020-11-23 14:43:56 status half-configured libgtk2.0-dev:amd64 2.24.32-4ubuntu4
2020-11-23 14:43:56 status installed libgtk2.0-dev:amd64 2.24.32-4ubuntu4
2020-11-23 14:43:56 configure libsys-hostname-long-perl:all 1.5-1 <none>
2020-11-23 14:43:56 status unpacked libsys-hostname-long-perl:all 1.5-1
2020-11-23 14:43:56 status half-configured libsys-hostname-long-perl:all 1.5-1
2020-11-23 14:43:56 status installed libsys-hostname-long-perl:all 1.5-1
2020-11-23 14:43:56 configure libfile-stripnondeterminism-perl:all 1.7.0-1 <none>
2020-11-23 14:43:56 status unpacked libfile-stripnondeterminism-perl:all 1.7.0-1
2020-11-23 14:43:57 status half-configured libfile-stripnondeterminism-perl:all 1.7.0-1
2020-11-23 14:43:57 status installed libfile-stripnondeterminism-perl:all 1.7.0-1
2020-11-23 14:43:57 configure gir1.2-wnck-1.0:amd64 1:2.30.7-5.1ubuntu1 <none>
2020-11-23 14:43:57 status unpacked gir1.2-wnck-1.0:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:57 status half-configured gir1.2-wnck-1.0:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:57 status installed gir1.2-wnck-1.0:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:57 configure libmail-sendmail-perl:all 0.80-1 <none>
2020-11-23 14:43:57 status unpacked libmail-sendmail-perl:all 0.80-1
2020-11-23 14:43:57 status half-configured libmail-sendmail-perl:all 0.80-1
2020-11-23 14:43:57 status installed libmail-sendmail-perl:all 0.80-1
2020-11-23 14:43:57 configure dh-strip-nondeterminism:all 1.7.0-1 <none>
2020-11-23 14:43:57 status unpacked dh-strip-nondeterminism:all 1.7.0-1
2020-11-23 14:43:57 status half-configured dh-strip-nondeterminism:all 1.7.0-1
2020-11-23 14:43:57 status installed dh-strip-nondeterminism:all 1.7.0-1
2020-11-23 14:43:57 configure libwnck-dev:amd64 1:2.30.7-5.1ubuntu1 <none>
2020-11-23 14:43:57 status unpacked libwnck-dev:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:57 status half-configured libwnck-dev:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:58 status installed libwnck-dev:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:43:58 configure dh-autoreconf:all 19 <none>
2020-11-23 14:43:58 status unpacked dh-autoreconf:all 19
2020-11-23 14:43:58 status half-configured dh-autoreconf:all 19
2020-11-23 14:43:58 status installed dh-autoreconf:all 19
2020-11-23 14:43:58 configure debhelper:all 12.10ubuntu1 <none>
2020-11-23 14:43:58 status unpacked debhelper:all 12.10ubuntu1
2020-11-23 14:43:58 status half-configured debhelper:all 12.10ubuntu1
2020-11-23 14:43:58 status installed debhelper:all 12.10ubuntu1
2020-11-23 14:43:58 trigproc man-db:amd64 2.9.1-1 <none>
2020-11-23 14:43:58 status half-configured man-db:amd64 2.9.1-1
2020-11-23 14:44:22 status installed man-db:amd64 2.9.1-1
2020-11-23 14:44:22 trigproc doc-base:all 0.10.9 <none>
2020-11-23 14:44:22 status half-configured doc-base:all 0.10.9
2020-11-23 14:44:25 status installed doc-base:all 0.10.9
2020-11-23 14:44:25 trigproc libc-bin:amd64 2.31-0ubuntu9.1 <none>
2020-11-23 14:44:25 status half-configured libc-bin:amd64 2.31-0ubuntu9.1
2020-11-23 14:44:26 status installed libc-bin:amd64 2.31-0ubuntu9.1
2020-11-23 14:48:34 startup packages remove
2020-11-23 14:48:34 status installed libwnck-dev:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:48:35 remove libwnck-dev:amd64 1:2.30.7-5.1ubuntu1 <none>
2020-11-23 14:48:35 status half-configured libwnck-dev:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:48:35 status half-installed libwnck-dev:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:48:35 status config-files libwnck-dev:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:48:35 status not-installed libwnck-dev:amd64 <none>
2020-11-23 14:48:36 startup packages configure
2020-11-23 14:49:03 startup archives unpack
2020-11-23 14:49:05 install libwnck-3-dev:amd64 <none> 3.36.0-1
2020-11-23 14:49:05 status half-installed libwnck-3-dev:amd64 3.36.0-1
2020-11-23 14:49:06 status unpacked libwnck-3-dev:amd64 3.36.0-1
2020-11-23 14:49:07 startup packages configure
2020-11-23 14:49:07 configure libwnck-3-dev:amd64 3.36.0-1 <none>
2020-11-23 14:49:07 status unpacked libwnck-3-dev:amd64 3.36.0-1
2020-11-23 14:49:07 status half-configured libwnck-3-dev:amd64 3.36.0-1
2020-11-23 14:49:07 status installed libwnck-3-dev:amd64 3.36.0-1
2020-11-23 14:57:13 startup packages remove
2020-11-23 14:57:13 status installed dh-autoreconf:all 19
2020-11-23 14:57:13 status installed debhelper:all 12.10ubuntu1
2020-11-23 14:57:13 status installed dh-strip-nondeterminism:all 1.7.0-1
2020-11-23 14:57:13 status installed dwz:amd64 0.13-5
2020-11-23 14:57:14 status installed libgtk2.0-dev:amd64 2.24.32-4ubuntu4
2020-11-23 14:57:15 remove libgtk2.0-dev:amd64 2.24.32-4ubuntu4 <none>
2020-11-23 14:57:15 status half-configured libgtk2.0-dev:amd64 2.24.32-4ubuntu4
2020-11-23 14:57:15 status half-installed libgtk2.0-dev:amd64 2.24.32-4ubuntu4
2020-11-23 14:57:15 status triggers-pending man-db:amd64 2.9.1-1
2020-11-23 14:57:15 status config-files libgtk2.0-dev:amd64 2.24.32-4ubuntu4
2020-11-23 14:57:16 status not-installed libgtk2.0-dev:amd64 <none>
2020-11-23 14:57:16 status installed gir1.2-wnck-1.0:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:57:16 remove gir1.2-wnck-1.0:amd64 1:2.30.7-5.1ubuntu1 <none>
2020-11-23 14:57:16 status half-configured gir1.2-wnck-1.0:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:57:16 status half-installed gir1.2-wnck-1.0:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:57:16 status config-files gir1.2-wnck-1.0:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:57:16 status not-installed gir1.2-wnck-1.0:amd64 <none>
2020-11-23 14:57:16 status installed gir1.2-gtk-2.0:amd64 2.24.32-4ubuntu4
2020-11-23 14:57:17 remove gir1.2-gtk-2.0:amd64 2.24.32-4ubuntu4 <none>
2020-11-23 14:57:17 status half-configured gir1.2-gtk-2.0:amd64 2.24.32-4ubuntu4
2020-11-23 14:57:17 status half-installed gir1.2-gtk-2.0:amd64 2.24.32-4ubuntu4
2020-11-23 14:57:17 status config-files gir1.2-gtk-2.0:amd64 2.24.32-4ubuntu4
2020-11-23 14:57:17 status not-installed gir1.2-gtk-2.0:amd64 <none>
2020-11-23 14:57:17 status installed libarchive-cpio-perl:all 0.10-1
2020-11-23 14:57:17 remove libarchive-cpio-perl:all 0.10-1 <none>
2020-11-23 14:57:17 status half-configured libarchive-cpio-perl:all 0.10-1
2020-11-23 14:57:17 status half-installed libarchive-cpio-perl:all 0.10-1
2020-11-23 14:57:18 status config-files libarchive-cpio-perl:all 0.10-1
2020-11-23 14:57:18 status not-installed libarchive-cpio-perl:all <none>
2020-11-23 14:57:18 status installed libdebhelper-perl:all 12.10ubuntu1
2020-11-23 14:57:18 status installed libfile-stripnondeterminism-perl:all 1.7.0-1
2020-11-23 14:57:18 status installed libmail-sendmail-perl:all 0.80-1
2020-11-23 14:57:18 remove libmail-sendmail-perl:all 0.80-1 <none>
2020-11-23 14:57:18 status half-configured libmail-sendmail-perl:all 0.80-1
2020-11-23 14:57:18 status half-installed libmail-sendmail-perl:all 0.80-1
2020-11-23 14:57:18 status config-files libmail-sendmail-perl:all 0.80-1
2020-11-23 14:57:19 status not-installed libmail-sendmail-perl:all <none>
2020-11-23 14:57:19 status installed libwnck-3-dev:amd64 3.36.0-1
2020-11-23 14:57:19 remove libwnck-3-dev:amd64 3.36.0-1 <none>
2020-11-23 14:57:19 status half-configured libwnck-3-dev:amd64 3.36.0-1
2020-11-23 14:57:19 status half-installed libwnck-3-dev:amd64 3.36.0-1
2020-11-23 14:57:19 status config-files libwnck-3-dev:amd64 3.36.0-1
2020-11-23 14:57:20 status not-installed libwnck-3-dev:amd64 <none>
2020-11-23 14:57:20 status installed libstartup-notification0-dev:amd64 0.12-6
2020-11-23 14:57:20 remove libstartup-notification0-dev:amd64 0.12-6 <none>
2020-11-23 14:57:20 status half-configured libstartup-notification0-dev:amd64 0.12-6
2020-11-23 14:57:20 status half-installed libstartup-notification0-dev:amd64 0.12-6
2020-11-23 14:57:20 status config-files libstartup-notification0-dev:amd64 0.12-6
2020-11-23 14:57:20 status not-installed libstartup-notification0-dev:amd64 <none>
2020-11-23 14:57:20 status installed libsub-override-perl:all 0.09-2
2020-11-23 14:57:21 status installed libsys-hostname-long-perl:all 1.5-1
2020-11-23 14:57:21 remove libsys-hostname-long-perl:all 1.5-1 <none>
2020-11-23 14:57:21 status half-configured libsys-hostname-long-perl:all 1.5-1
2020-11-23 14:57:21 status half-installed libsys-hostname-long-perl:all 1.5-1
2020-11-23 14:57:21 status config-files libsys-hostname-long-perl:all 1.5-1
2020-11-23 14:57:21 status not-installed libsys-hostname-long-perl:all <none>
2020-11-23 14:57:21 status installed libwnck22:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:57:21 remove libwnck22:amd64 1:2.30.7-5.1ubuntu1 <none>
2020-11-23 14:57:21 status triggers-pending libc-bin:amd64 2.31-0ubuntu9.1
2020-11-23 14:57:22 status half-configured libwnck22:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:57:22 status half-installed libwnck22:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:57:22 status config-files libwnck22:amd64 1:2.30.7-5.1ubuntu1
2020-11-23 14:57:22 status not-installed libwnck22:amd64 <none>
2020-11-23 14:57:22 status installed libwnck-common:all 1:2.30.7-5.1ubuntu1
2020-11-23 14:57:22 remove libwnck-common:all 1:2.30.7-5.1ubuntu1 <none>
2020-11-23 14:57:22 status half-configured libwnck-common:all 1:2.30.7-5.1ubuntu1
2020-11-23 14:57:22 status half-installed libwnck-common:all 1:2.30.7-5.1ubuntu1
2020-11-23 14:57:23 status config-files libwnck-common:all 1:2.30.7-5.1ubuntu1
2020-11-23 14:57:23 status not-installed libwnck-common:all <none>
2020-11-23 14:57:23 status installed libxres-dev:amd64 2:1.2.0-4
2020-11-23 14:57:23 remove libxres-dev:amd64 2:1.2.0-4 <none>
2020-11-23 14:57:23 status half-configured libxres-dev:amd64 2:1.2.0-4
2020-11-23 14:57:23 status half-installed libxres-dev:amd64 2:1.2.0-4
2020-11-23 14:57:23 status config-files libxres-dev:amd64 2:1.2.0-4
2020-11-23 14:57:24 status not-installed libxres-dev:amd64 <none>
2020-11-23 14:57:24 status installed po-debconf:all 1.0.21
2020-11-23 14:57:25 remove debhelper:all 12.10ubuntu1 <none>
2020-11-23 14:57:25 status half-configured debhelper:all 12.10ubuntu1
2020-11-23 14:57:25 status half-installed debhelper:all 12.10ubuntu1
2020-11-23 14:57:26 status config-files debhelper:all 12.10ubuntu1
2020-11-23 14:57:26 status not-installed debhelper:all <none>
2020-11-23 14:57:26 remove dh-strip-nondeterminism:all 1.7.0-1 <none>
2020-11-23 14:57:26 status half-configured dh-strip-nondeterminism:all 1.7.0-1
2020-11-23 14:57:26 status half-installed dh-strip-nondeterminism:all 1.7.0-1
2020-11-23 14:57:26 status config-files dh-strip-nondeterminism:all 1.7.0-1
2020-11-23 14:57:27 status not-installed dh-strip-nondeterminism:all <none>
2020-11-23 14:57:27 remove dwz:amd64 0.13-5 <none>
2020-11-23 14:57:27 status half-configured dwz:amd64 0.13-5
2020-11-23 14:57:27 status half-installed dwz:amd64 0.13-5
2020-11-23 14:57:27 status config-files dwz:amd64 0.13-5
2020-11-23 14:57:27 status not-installed dwz:amd64 <none>
2020-11-23 14:57:28 remove libdebhelper-perl:all 12.10ubuntu1 <none>
2020-11-23 14:57:28 status half-configured libdebhelper-perl:all 12.10ubuntu1
2020-11-23 14:57:28 status half-installed libdebhelper-perl:all 12.10ubuntu1
2020-11-23 14:57:28 status config-files libdebhelper-perl:all 12.10ubuntu1
2020-11-23 14:57:28 status not-installed libdebhelper-perl:all <none>
2020-11-23 14:57:28 remove libfile-stripnondeterminism-perl:all 1.7.0-1 <none>
2020-11-23 14:57:28 status half-configured libfile-stripnondeterminism-perl:all 1.7.0-1
2020-11-23 14:57:28 status half-installed libfile-stripnondeterminism-perl:all 1.7.0-1
2020-11-23 14:57:29 status config-files libfile-stripnondeterminism-perl:all 1.7.0-1
2020-11-23 14:57:29 status not-installed libfile-stripnondeterminism-perl:all <none>
2020-11-23 14:57:29 remove libsub-override-perl:all 0.09-2 <none>
2020-11-23 14:57:29 status half-configured libsub-override-perl:all 0.09-2
2020-11-23 14:57:29 status half-installed libsub-override-perl:all 0.09-2
2020-11-23 14:57:29 status config-files libsub-override-perl:all 0.09-2
2020-11-23 14:57:30 status not-installed libsub-override-perl:all <none>
2020-11-23 14:57:30 remove po-debconf:all 1.0.21 <none>
2020-11-23 14:57:30 status half-configured po-debconf:all 1.0.21
2020-11-23 14:57:30 status half-installed po-debconf:all 1.0.21
2020-11-23 14:57:30 status triggers-pending doc-base:all 0.10.9
2020-11-23 14:57:30 status config-files po-debconf:all 1.0.21
2020-11-23 14:57:30 status not-installed po-debconf:all <none>
2020-11-23 14:57:31 remove dh-autoreconf:all 19 <none>
2020-11-23 14:57:31 status half-configured dh-autoreconf:all 19
2020-11-23 14:57:31 status half-installed dh-autoreconf:all 19
2020-11-23 14:57:31 status config-files dh-autoreconf:all 19
2020-11-23 14:57:31 status not-installed dh-autoreconf:all <none>
2020-11-23 14:57:32 startup packages configure
2020-11-23 14:57:32 trigproc libc-bin:amd64 2.31-0ubuntu9.1 <none>
2020-11-23 14:57:32 status half-configured libc-bin:amd64 2.31-0ubuntu9.1
2020-11-23 14:57:32 status installed libc-bin:amd64 2.31-0ubuntu9.1
2020-11-23 14:57:32 trigproc man-db:amd64 2.9.1-1 <none>
2020-11-23 14:57:32 status half-configured man-db:amd64 2.9.1-1
2020-11-23 14:57:35 status installed man-db:amd64 2.9.1-1
2020-11-23 14:57:35 trigproc doc-base:all 0.10.9 <none>
2020-11-23 14:57:35 status half-configured doc-base:all 0.10.9
2020-11-23 14:57:36 status installed doc-base:all 0.10.9

答案1

第一种方法:

每个文件使用多个单词行(file1file2file3

为了解决这个问题,让它list1成为使用第一个命令生成的文件:

cat /var/log/dpkg.log | awk '/ installed / && /2020-11-23 14:/ {print $5}' | awk '{printf "%s ", gensub(/:.*/,"\\1", "g", $1); }' | tr ' ' '\n' > list1

list2成为使用第二条命令生成的文件:

cat /var/log/dpkg.log | awk '/ trigproc / && /2020-11-23 14:/ {print $4}' | awk '{printf "%s ", gensub(/:.*/,"\\1", "g", $1); }' | tr ' ' '\n' > list2

在这两个文件中,空格都使用 转换为换行符tr,以便每行有一个单词。

file3然后,可以使用以下命令生成第三个文件awk

awk 'FNR==1{nf++} ; nf==1{a[$1]=1;next} ; a[$1]==0{print}' list2 list1 > list3

file3file1应包含除 中提到的所有词语file2


第二种方法:

每个文件使用单个多字行(single1single2single3

在这种情况下,让它single1成为使用原始帖子的第一个命令生成的文件awk

cat /var/log/dpkg.log | awk '/ installed / && /2020-11-23 14:/ {print $5}' | awk '{printf "%s ", gensub(/:.*/,"\\1", "g", $1); }' > single1

single2成为使用原始帖子的第二个命令生成的文件awk

cat /var/log/dpkg.log | awk '/ trigproc / && /2020-11-23 14:/ {print $4}' | awk '{printf "%s ", gensub(/:.*/,"\\1", "g", $1); }' > list2

这两个文件(single1single2)都有一个多字行,没有新队在最后。

single3然后,可以使用以下命令生成第三个文件awk

awk 'FNR==1{nf++} ; nf==1{for (i=1;i<=NF;i++) a[$i]=1} ; nf==2{for (i=1;i<NF;i++) if (a[$i]==0) printf "%s ",$i}' list2 list1 > list3

single3single1应包含除 中提到的所有词语single2

相关内容