.desktop files contain loads and loads of lines that are not needed.
e.g:-
GenericName[es]=Navegador web
Comment[ca]=Accedeix a Internet
Name[fr]=Nouvelle fenêtre
ad nauseam - take a look at the google-chrome.desktop attached and you'll see what I mean.
I don't need any of these language entries and in the past I used to manually clean up those that I used the most to improve execution times. That was back in the days of a 486 with 500mb RAM and an 80gb hard drive!!!!
Now, I have tried using various combinations of sed to find and remove these but I keep running into the same problem and that is the [ ]s which are seen as regex entries. Obviously what I want to do is find any line that contains Name[anything]= or Comment[anything]= and so on and delete the line.
This would leave lines like
Comment=Access the Internet intact - which is what I want.
I have searched for finding lines with variables or wildcards but keep stumbling on the square brackets. Anyone got any ideas please? I have tried various find utilities but this needs to be programmatic to handle the number of files involved.
Thanx - bin
Find and delete lines in .desktop files
Find and delete lines in .desktop files
- Attachments
-
- google-chrome.desktop.zip
- (3.78 KiB) Downloaded 231 times
Re: Find and delete lines in .desktop files
Code: Select all
grep -v '.*\[.*\]=' textmaker-free18.desktop
will print ONLY lines NOT containing:
Something[something]= from the file textmaker-free18.desktop
Note the \ escaping [ and ], and .* for any-length string
Re: Find and delete lines in .desktop files
Excellent - find what you're not looking for! No wonder I struggle with this stuff!chris wrote: ↑Thu Aug 06, 2020 8:41 pm[/size]Code: Select all
grep -v '.*\[.*\]=' textmaker-free18.desktop
will print ONLY lines NOT containing:
Something[something]= from the file textmaker-free18.desktop
Note the \ escaping [ and ], and .* for any-length string
From there it's just a quick leap to
Code: Select all
sed -i /'.*\[.*\]=/d' sol.desktop
Code: Select all
sudo sed -i /'.*\[.*\]=/d' *.desktop
Thanks very much chris!
Re: Find and delete lines in .desktop files
A safer way to do what you want:
And then restart to make sure your "new" .desktop files are working. Only then delete the .backup files
Code: Select all
for i in *.desktop; do cp "$i" "$i.backup"; grep -v '.*\[.*\]=' "$i.backup" > "$i"; done
Re: Find and delete lines in .desktop files
Good thinking.
I was puzzled by the use of grep but a bit more digging with a relevant example makes it a lot clearer. Thanks again for assisting my little grey cell!
If anyone is reading this and wondering what I'm on about - please see the before and after attached.
221 lines down to 25 lines to be read each time it is used.
I was puzzled by the use of grep but a bit more digging with a relevant example makes it a lot clearer. Thanks again for assisting my little grey cell!
If anyone is reading this and wondering what I'm on about - please see the before and after attached.
221 lines down to 25 lines to be read each time it is used.
- Attachments
-
- chrome desktop files.zip
- Beffore and after files renamed with txt extension.
- (4.44 KiB) Downloaded 217 times
- dai_trying
- Posts: 634
- Joined: Sun Jan 14, 2018 7:44 pm
- Location: UK
- Contact:
Re: Find and delete lines in .desktop files
I tried it when I first read this post, and it sure makes editing .desktop files easier! Thank you both
Re: Find and delete lines in .desktop files
As an aside/addition if you change the grep bit to:
you get rid of blank lines too.
Note capital E and vertical bar separator between regex bits.
Code: Select all
grep -v -E '.*\[.*\]=|^$' "filename"
Note capital E and vertical bar separator between regex bits.
Re: Find and delete lines in .desktop files
Thanks for that chris - a useful extra tweak.
Well, I ran the cleanup and certainly things do feel a bit snappier - especially Konqueror. It may be a placebo effect of course!! But, it still results in a much cleaner system and that I like.
I did try to find a way to make the script recursive, but couldn't get ant sort of -r switch to work. So, I did it old school by finding the folders with .desktop files, created a script tp run on each folder *.desktop and that worked OK. I excluded my /home so that's next
Well, I ran the cleanup and certainly things do feel a bit snappier - especially Konqueror. It may be a placebo effect of course!! But, it still results in a much cleaner system and that I like.
I did try to find a way to make the script recursive, but couldn't get ant sort of -r switch to work. So, I did it old school by finding the folders with .desktop files, created a script tp run on each folder *.desktop and that worked OK. I excluded my /home so that's next