Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 2312  / 1 Year ago, fri, november 11, 2022, 8:21:11

After running these two commands:



sudo apt-get install ubuntu-desktop
sudo apt-get remove ubuntu-desktop


I am left with a glut of installed packages that I don't need/want on my Lubuntu install. I just wanted to see how Unity performed under Lubuntu.



I've discovered I can view the list of installed programs by looking at my /var/log/apt/history.log



I'd like to simply cut and paste this list into a sudo apt-get remove command but first I need to delete the portions apt-get won't understand. Basically everything inside the parenthesis (including parenthesis themselves) needs to go. Additionally the following comma and space after each entry will also need deleting.



The closest I've come with sed so far is:



sed -e 's/(.*),[[:space:]]//g' apt-log.txt


This is not right since it deletes almost everything. I presume this is because its matching the very last instance of "), " and deleting everything before it until "(". Here's a link to program list from the log I'm trying to edit.



As you can imagine, I would rather not edit that list by hand. I know next to nothing about regular expressions and am trying to learn but a few specific pointers would go a long way. Or maybe there's a much better way to go about this?


More From » apt

 Answers
5

Your problem with the regular expression is its greediness (the * and + quantifiers try to match as much, as they can). Unfortunately there is no way to tell sed to use non-greedy regular expressions. You have to use Perl to accomplish that, although ugly workarounds for sed do exist.



So try the following Perl one-liner:



perl -pe 's/(.*?)(, )?//g' /var/log/apt-history.log


That should manipulate the text as you wish. You will find PCRE (Perl regular expressions) very similar to the POSIX / GNU BRE and ERE one sed uses.


[#36148] Sunday, November 13, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
itagde

Total Points: 241
Total Questions: 113
Total Answers: 118

Location: Liechtenstein
Member since Wed, Dec 8, 2021
2 Years ago
itagde questions
Thu, Jun 10, 21, 21:24, 3 Years ago
Sat, Aug 13, 22, 22:41, 2 Years ago
Thu, May 20, 21, 11:52, 3 Years ago
Tue, Aug 23, 22, 06:19, 2 Years ago
;