You are not logged in.

#1 2025-08-17 03:09:46

wub
Member
Registered: 2025-08-14
Posts: 17

Modify or clean up pacman search output to simplify results

Hi All.
I am new to arch. Still settling in.
Loving a lot of it though. Maybe this is home now.

TBH I haven't read through all the pacman docu on the wiki (though there are several great articles I've bookmarked there). Will do, though I am short on time right now.

I am wondering, when searching packages with:
    pacman -Ss
   
I would like the output modified as follows, to simplify the results and clean up mess that is unnecessary to me.
I find the defaut output messy/confusing to the eye, especially if I am reviewing an output list that has more than 20 results or so (sometimes upwards of 100).

From the output, I would like to remove:
- package VERSION description,
- repo information (or append the repo info to the end of the line, rather than at the front).

This information is normally superfluous to me.

(I realize this kind of thing can be done with stream filtering tools like sed and awk, which I don't know how to use, but with debian's apt, the apt -cache option took care of this when searching, as in apt -cache search).

Something simple like this would be perfect.

$ pacman -Ss 
package name 1 : package description 
package name 2 : package description 

Or, with repo appended to the end, rather than at the front

$ pacman -Ss 
package name 1 : package description : repo [core/extra]
package name 2 : package description : repo [core/extra]


Further examples
-------------------------

Default output:

core/iptables 1:1.8.11-2
    Linux kernel packet control tool (using legacy interface)
core/iptables-nft 1:1.8.11-2 [installed]
    Linux kernel packet control tool (using nft interface)
core/libpcap 1.10.5-3 [installed]
    A system-independent interface for user-level packet capture
extra/dpdk 24.11.2-1
    A set of libraries and drivers for fast packet processing
extra/fwknop 2.6.11-1
    FireWall KNock OPerator: Single Packet Authorization and Port Knocking
extra/hcxdumptool 6.3.5-1
    Small tool to capture packets from wlan devices
extra/hping 3.0.0-6
    A command-line oriented TCP/IP packet assembler/analyzer.

Should preferably become something simpler like:

iptables        Linux kernel packet control tool (using legacy interface)
iptables-nft    Linux kernel packet control tool (using nft interface)
libpcap         A system-independent interface for user-level packet capture
dpdk            A set of libraries and drivers for fast packet processing
fwknop          FireWall KNock OPerator: Single Packet Authorization and Port Knocking
hcxdumptool     Small tool to capture packets from wlan devices
hping           A command-line oriented TCP/IP packet assembler/analyzer.

   
I typically don't have any need to know which repo, because if a repo is added, it is because I trust it (and typically I never add repos).
I also normally have no need for package version info.

In debian-based distros, something similar to this is accomplished simply with:

	apt -cache search <searchterm> 

The -cache option being the operative that simplifies out the results into a simple and easy to read package list with no superfluous mess like version numbers, release, repo, etc.

I referred to the arch wiki article on the "Pacman Rosetta" which is a great article, as well as pacman tips and tricks, and the general article, but could not find what I was looking for there.

Any help appreciated.
Thanks

Offline

#2 2025-08-17 08:42:19

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 14,315

Re: Modify or clean up pacman search output to simplify results

I typically don't have any need to know which repo, because if a repo is added, it is because I trust it (and typically I never add repos).

That will blur the difference between official repos, local repos and external 3rd party repos.  Pacman wrappers (usually called AUR helpers) do that and it's a major reason why those are disliked by many forum users.

I expect even adding  an (off by default) option to omit that info from --search output will be rejected by pacman devs.

I never used it myself, but you may be able to achieve the desired result by setting up an alias that uses --print-format .

man pacman wrote:

--print-format <format>
Specify a printf-like format to control the output of the --print operation. The possible attributes are: "%a" for arch, "%b" for builddate, "%d" for description, "%e" for pkgbase, "%f" for filename, "%g" for base64 encoded PGP signature, "%h" for sha256sum, "%m" for md5sum, "%n" for pkgname, "%p" for packager, "%v" for pkgver, "%l" for location, "%r" for repository, "%s" for size, "%C" for checkdepends, "%D" for depends, "%G" for groups, "%H" for conflicts, "%L" for licenses, "%M" for makedepends, "%O" for optional depends, "%P" for provides and "%R" for replaces. Implies --print.


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#3 2025-08-17 09:27:28

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 69,177

Re: Modify or clean up pacman search output to simplify results

I realize this kind of thing can be done with stream filtering tools like sed and awk

Yes.

which I don't know how to use

soo… awesome opportunity to change that?

pacman -Ss iptables | sed 's%\(core\|extra\)/\([^ ]*\).*%\2%g; :r;s/^[^ ].\{1,24\}$/& /;tr; :a;N;s/\n  */  /;ta;P;D'

You're now gonna figure what that does and explain it to me.
And I don't want to smell any chatgpt talking tongue

Homework: add colors.

Offline

#4 2025-08-17 15:25:54

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,520

Re: Modify or clean up pacman search output to simplify results

So lets do that in awk too then tongue

pacman -Ss iptables | awk -F '/| ' '/core|extra/{ printf "%-24s",$2; getline; print }'

@seth, I love those sed lines...

Offline

#5 2025-08-17 16:08:51

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 69,177

Re: Modify or clean up pacman search output to simplify results

You can get it easier w/ a sneaky "sed -z", but where's the fun with that? lol

Caveat on the awk: idk whether and what the pacman output looks like if there was no usable package description (though that's probably a theoretical issue)

Offline

#6 2025-08-17 16:31:47

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,520

Re: Modify or clean up pacman search output to simplify results

I'm not sure, but, wouldn't a next field solve that...?

pacman -Ss iptables | awk -F '/| ' '/core|extra/{ printf "%-24s",$2; getline; print; NF }'

Hahah don't go zed lol, btw I think this is append right ' :a;' you could remove it already does that


edit: actually tried it and it doesn't show blank space
Sed doesn't show that problem and nicely shows the block with 'blank' content, If I find the time I'll try and fix that

edit:
Well 'NF' on it's own wasn't enough, it needs to be replaced too
So this will only works if that blank line is actually printed

pacman -Ss iptables | awk -F '/| ' '/core|extra/{ printf "%-24s",$2; getline; print NF ? $0 : "" }'

Last edited by qinohe (2025-08-17 18:09:16)

Offline

#7 2025-08-17 21:25:05

NuSkool
Member
Registered: 2015-03-23
Posts: 276

Re: Modify or clean up pacman search output to simplify results

Another, arguably simpler or more complex option depending on your point of view....

The package 'expac' seems like a natural for custom output, combined with column in this case.

$ expac -Ss '%n : %d' iptables  | column -t -s':'

iptables            Linux kernel packet control tool (using legacy interface)
iptables-nft        Linux kernel packet control tool (using nft interface)
python-geoipsets    Tool to generate country-specific IP ranges for iptables/ipset and nftables
sshguard            Brute force detector for SSH, Exim, VSFTPD and more. Blocks by ip with iptables

Last edited by NuSkool (2025-08-17 21:43:32)


Scripts I Use                                                 :  https://github.com/Cody-Learner
grep -m1 'model name' /proc/cpuinfo    : AMD Ryzen 7 8745HS w/ Radeon 780M Graphics
grep -m1 'model name' /proc/cpuinfo    : Intel(R) N95
grep -m1 'model name' /proc/cpuinfo    : AMD Ryzen 5 PRO 2400GE w/ Radeon Vega Graphics

Offline

#8 2025-08-17 21:54:45

Succulent of your garden
Member
From: Majestic kingdom of pot plants
Registered: 2024-02-29
Posts: 873

Re: Modify or clean up pacman search output to simplify results

seth wrote:

pacman -Ss iptables | sed 's%\(core\|extra\)/\([^ ]*\).*%\2%g; :r;s/^[^ ].\{1,24\}$/& /;tr; :a;N;s/\n  */  /;ta;P;D'

I need to do my homework smile

I'll try during the two following weeks to understand that deeply[without LLM help of course]. Thanks seth for the challenge. Someone should make a T-shirt with this, and in the back of it should say: I was trained in the school of seth. Bugs just run away from me.

Last edited by Succulent of your garden (2025-08-17 21:55:18)


str( @soyg ) == str( @potplant ) btw!

Offline

#9 2025-08-22 07:21:50

wub
Member
Registered: 2025-08-14
Posts: 17

Re: Modify or clean up pacman search output to simplify results

Hi all. Thank you everybody for your swift, useful responses.
Pardon my late reply. I am juggling way too much, and my switchboard is overloaded.

------------------
@Lone_Wolf
------------------

That will blur the difference between official repos, local repos and external 3rd party repos.

I understand that (I think).
I don't add 3rd party repos. I just stick with the default that is there at install. Are the "Extra" repos that come installed by default a possible concern?

Your --print-format suggestion is interesting (why not just "printf"?). I'm not sure I understand the full context. I could conceivably get my head around that (looks very "c-like"), although not today.

----------
@seth
----------
Thanks very much for your response, and for your awesome little filter script!
I could create an alias for that, and yay! Probably problem solved.

I was hoping for something like this.

I agree with you. Now is an awesome opportunity to change many things in my life and about myself which are not as great as they could be, and are lacking.

Unfortunately, I am a substandard factory-second badly-programmed totally-defective robot with minimal specs who only has the bandwidth to focus on changing one complex (to me) thing at a time, and right now there are other pressing things that are eating at me.

As mentioned, with apt, there is the -cache option for this purpose. I was just hoping for something similar, as I don't have time to RTFM completely on anything today, or probably for the next 3+ of months, as my reading and study is cut out for me.
Though, I look forward to the day I do educate myself on sed, apt, and about a million other things in the gnu toolbox. Maybe even lower-level than that. But I might be dreaming about time I don't have.
(I do actually have files for this on-drive, waiting for me to read.)

However, the sed string you wrote is perfect, and an alias for that will do just fine, I think!

I hope to explain it back to you sometime. Promise I won't use "AI". I f-----ng hate "AI" (and the "I" in "AI" is a misnomer anyway, isn't it?). I only use LLMs if I am reeeaaally stuck on something. I mean, I guess I could have used it here. But "where is the fun in that"?

--------------
@qinohe
--------------
haha, now you are all showing off! (Or at least, from my place of ignorance, it would appear so).
Awk seems like it might be a bit more elegant for this sort of thing, but I have no idea why.

------------------------------------------------------------
@NuSkool and @Succulent of your garden
------------------------------------------------------------
Thanks everybody else.
Although I think you are all talking well above my paygrade for the moment! 0__0 
(I assume these are general contributions, not necessarily directed at me, anyway).
I will come back here someday and review this and see if I can understand it, I am sure.
Thanks!

Anyway, thank you everybody.
I like this place.

Last edited by wub (2025-08-22 07:44:35)

Offline

#10 2025-08-22 07:52:13

wub
Member
Registered: 2025-08-14
Posts: 17

Re: Modify or clean up pacman search output to simplify results

Oh, the one extra bit of info these filters could (hopefully) include is whether the package is already installed or not. I guess I could LLM that info, but then I wouldn't get to bother the hard-thinking arch people about it (:

Last edited by wub (2025-08-22 07:53:22)

Offline

#11 2025-08-22 08:29:59

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 14,315

Re: Modify or clean up pacman search output to simplify results

wub wrote:

package is already installed or not

Most (all ? ) of the search outputs add the version when a pacakge is installed .

wub wrote:

I don't add 3rd party repos. I just stick with the default that is there at install. Are the "Extra" repos that come installed by default a possible concern?

That part was more meant as  a warning for other readers as blurring the distinction between official , aur and 3rd party is often missed.
[core] & [extra] are maintained by the same people* and both official repositories.

Sidenote:
No need to apologise for delays in answering , all of us are volunteers that have lives.





* new devs are not allowed to push to core until they've been a dev for some months.


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#12 2025-08-22 13:53:29

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 69,177

Re: Modify or clean up pacman search output to simplify results

Ask your AI to explain this…

LC_ALL=C pacman -Ss iptables | sed 's%/\([^ ]*\)%/\x1b\[34m\1\x1b\[0m%; /\[installed\]/s%\x1b\[34m%\x1b\[32m%; s%\(core\|extra\)/\([^ ]*\).*%\2%g; :r;s/^[^ ].\{1,32\}$/& /;tr; :a;N;s/\n  */  /;ta;P;D'

Offline

#13 2025-08-22 14:42:04

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,520

Re: Modify or clean up pacman search output to simplify results

@seth, this what I got from the AI, maybe not perfect yet, but wait a few years...

Duckduck AI's answer:

GPT-4o mini(smaller version of OpenAI's GPT-4o model)

The command you've provided is a complex shell command that utilizes `pacman`, `sed`, and other shell utilities to search for `iptables` packages in the Arch Linux package manager. Here's a breakdown of what each part does:

1. **`LC_ALL=C`**: This sets the locale to the default C locale, which can help ensure consistent output formatting.

2. **`pacman -Ss iptables`**: This command searches for packages related to `iptables` in the Arch Linux repositories. The `-S` option is for searching, and the second `-s` indicates a case-insensitive search.

3. **`| sed '...'`**: The output of the `pacman` command is piped into `sed`, which is a stream editor used for parsing and transforming text.

4. **`s%/\([^ ]*\)%/\x1b\[34m\1\x1b\[0m%`**: This substitution command changes the color of the package names to blue by wrapping them in ANSI escape codes.

5. **`/\[installed\]/s%\x1b\[34m%\x1b\[32m%`**: This changes the color of installed packages to green.

6. **`s%\(core\|extra\)/\([^ ]*\).*%\2%g`**: This removes the repository prefix (`core/` or `extra/`) from the package names.

7. **`:r;s/^[^ ].\{1,32\}$/&amp; /;tr;`**: This part seems to be attempting to format the output further, possibly adding HTML entities or formatting.

8. **`:a;N;s/\n  */  /;ta;P;D`**: This is a loop that processes the output to combine lines and format them correctly.

### Summary of the Command's Purpose
The overall purpose of this command is to search for `iptables` packages in the Arch Linux repositories, format the output to highlight package names and installed packages, and clean up the display for better readability.

If you have specific questions about any part of this command or need help with a particular aspect, feel free to ask!

Offline

#14 2025-08-22 15:26:56

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 69,177

Re: Modify or clean up pacman search output to simplify results

The `-S` option is for searching, and the second `-s` indicates a case-insensitive search.

Interesting that it struggles on that - rtfm, gpt tongue
(I got a slightly better reply?)

This part seems to be attempting to format the output further, possibly adding HTML entities or formatting.

… and it seems black-belt sed isn't sufficiently covered by stackoverflow lol
(Though it gave a better breakdown here, did you both the "&amp;" ?)

But it knows what the pacman output would look like, so it can interpret the edited segments.

Now here's the thing, it more or less correctly and similarly explains

LC_ALL=C pacman -Ss iptables | sed 's%/\([^ ]*\)%/\x1b\[34m\1\x1b\[0m%; /\[installed\]/s%\x1b\[34m/\x1b\[32m%; s%\(core\|extra\)/\([^ ]*\).*%\2%g; :r;s/^[^ ].\{1,32\}$/& /;tr; :a;N;s/\n  */  /;ta;P;D'

but there's an error because I forgot midway that I was using "%" as command segmentation and not "/" which the AI blatantly ignores.

Offline

#15 2025-08-22 15:32:16

Succulent of your garden
Member
From: Majestic kingdom of pot plants
Registered: 2024-02-29
Posts: 873

Re: Modify or clean up pacman search output to simplify results

seth wrote:

Interesting that it struggles on that - rtfm, gpt tongue

LLM: Seth vector can't be found in the hyperplane, therefore I must say whatever thing to satisfy the hooman needs. print print print brrr


str( @soyg ) == str( @potplant ) btw!

Offline

#16 2025-08-22 16:25:08

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,520

Re: Modify or clean up pacman search output to simplify results

… and it seems black-belt sed isn't sufficiently covered by stackoverflow lol
(Though it gave a better breakdown here, did you both the "&amp;" ?)

Hahahah, I did no such thing lol
Gpt did that completely on it's own,'it' probably thought WITISUS(what I think I see U see) tongue

But it knows what the pacman output would look like, so it can interpret the edited segments.

The beauty of it all.....

I was using "%" as command segmentation and not "/" which the AI blatantly ignores.

Better use shellcheck for the time being...

Offline

#17 2025-08-22 16:41:42

Succulent of your garden
Member
From: Majestic kingdom of pot plants
Registered: 2024-02-29
Posts: 873

Re: Modify or clean up pacman search output to simplify results

LC_ALL=C pacman -Ss iptables | sed 's%/\([^ ]*\)%/\x1b\[34m\1\x1b\[0m%; /\[installed\]/s%\x1b\[34m/\x1b\[32m%; s%\(core\|extra\)/\([^ ]*\).*%\2%g; :r;s/^[^ ].\{1,32\}$/& /;tr; :a;N;s/\n  */  /;ta;P;D'

I'm not joking, but that just killed anything-LLM + gpt-oss:20b lol  The message output is:

Could not respond to message.
llama runner process has terminated: exit status 2

Every time you ask: explain this: [insert seth line] the program just stop. Simply they don't want to go into that lol

I had to ask the question running open source gpt in terminal. That way I was able to get the output. I haven't read it yet, I'm trying to do my homework tongue, but I was curious about what would gpt open source could tell about it.

btw do you recommend some temporally image uploader page that is not imgur ?

Last edited by Succulent of your garden (2025-08-22 16:42:38)


str( @soyg ) == str( @potplant ) btw!

Offline

#18 2025-08-22 18:47:31

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 69,177

Re: Modify or clean up pacman search output to simplify results

If you don't overdo it you can just upload images to 0x0.st as well, but there're really countless image pasting services (just google/ddg for that)

Offline

#19 2025-08-23 13:25:22

Succulent of your garden
Member
From: Majestic kingdom of pot plants
Registered: 2024-02-29
Posts: 873

Re: Modify or clean up pacman search output to simplify results

Thanks, I didn't knew that 0x0 could be use for that. Do you recommend some others that will not last the images forever ?


str( @soyg ) == str( @potplant ) btw!

Offline

#20 2025-08-23 14:13:55

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 69,177

Re: Modify or clean up pacman search output to simplify results

0x0.st has a time quota and, as most services, allow you to delete posts (you can get a token w/ the paste which allows you to remove it)

Offline

#21 2025-08-23 14:29:17

Succulent of your garden
Member
From: Majestic kingdom of pot plants
Registered: 2024-02-29
Posts: 873

Re: Modify or clean up pacman search output to simplify results

Okey thanks Seth, I didn't know 0x0 until this week. seems fine smile


str( @soyg ) == str( @potplant ) btw!

Offline

#22 2025-08-24 14:08:10

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,520

Re: Modify or clean up pacman search output to simplify results

@seth, I couldn't stay behind and had to make the awk equivalent for that sed command tongue
First time I use ANSI escape in an awk command

pacman -Ss iptables | awk -F '/| ' '/core|extra/{ if ($4 ~ /installed/) printf "\033[32m" "%-27s", $2 "\033[0m"; else printf "\033[34m" "%-27s", $2 "\033[0m"; getline; print}'

About that 'Description', you can make a PKGBUILD w/o it and it builds just fine
However, running the thing through 'namcap' gives an error
So I think uploading a PKGBUILD w/o description isn't allowed?

Offline

#23 2025-08-24 14:15:33

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 69,177

Re: Modify or clean up pacman search output to simplify results

So I think uploading a PKGBUILD w/o description isn't allowed?

"Idk"
https://wiki.archlinux.org/title/AUR_su … guidelines doesn't mention it, https://wiki.archlinux.org/title/Arch_p … guidelines talks about "when", not "if" which might imply that one should add one (and you actually should because it's rather useful)
But idk happens if you don't.
And, tbh, for a practical local solution I'd make bold assumptions about the output format and then of course use awk (because that's what's its for) - building complex sed strings to scare people is just also much more fun lol

Offline

#24 2025-08-24 14:31:25

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,520

Re: Modify or clean up pacman search output to simplify results

Yes, I already read trough all those pages and came to the same conclusion you did

building complex sed strings to scare people is just also much more fun lol

Hahah I like it, they are a beautiful piece of work, indeed waaaay more complicated to explain to the public lol

Offline

#25 2025-08-24 16:27:25

Succulent of your garden
Member
From: Majestic kingdom of pot plants
Registered: 2024-02-29
Posts: 873

Re: Modify or clean up pacman search output to simplify results

seth wrote:

  building complex sed strings to scare people is just also much more fun lol

qinohe wrote:

Hahah I like it, they are a beautiful piece of work, indeed waaaay more complicated to explain to the public lol

I'm considering seriously to make me a couple of cups with both commands printed, or one in the back of the cup and the other in the front. So each day I'll see that and  I will be remembering what meant, so in the not distant future the patterns will be written in my  head forever, and became a better text manipulator.

The T-shirt maybe, If I need to scare mediocre people in job or studying with me, and attracting big brains lol

Last edited by Succulent of your garden (2025-08-24 16:27:59)


str( @soyg ) == str( @potplant ) btw!

Offline

Board footer

Powered by FluxBB