I am trying to produce a script which at some point needs to grep a command’s output in order to retrieve some value.
Example:
my-key : my-data
other-key: other-data
Where I am interested in getting the value “my-data”.
So far I’ve been able to deal with that kind of input, but I recently discovered that input can come differently:
my-key : my data1
my-data2
my-data3
other-key: other-data
Where I am interested in getting “my-data1” “my-data2” and “my-data3”.
Is there a way of telling grep to get those values for me? If not, what about awk or even sed?
And just in case, this is NOT homework. In fact, I finished University 15 years ago (I am currently 37 years old).
What I am trying to produce is a simple script that finds all packages that (optionally/mandatory) require a given package by parsing pacman’s (pacman -Qi) output.
Hi Tio I’ve just tried this not sure what you’re after but this caused a few headaches. Far from an awk guru or sed but this seems to work. But you still have some rubbish in opt deps.
What this does from my crude understanding RS = set the record selector to “Optional Deps” and set the FS = field marker to “Required By” and print field 1 .
There still is a few niggles to iron out i.e the first record for me is wrong it includes too much and ends with depends on so will need trimming(Maybe you can remove those lines, something like line doesn’t begin with alpha or line begins with whitespace in regexp). Then the other problem is you’ll still end up with things like.
: gamin: a fam replacement to make thunar monitor changes to
files on the fly
xfce4-panel: for trash applet
Not to mention I presume eventually you’ll want to collect the app name to. But certainly think awk maybe the better tool for what you wish for.
Just pure awk apologies for the superfluous use of pipes one day I’ll actually work out that bit. It runs a lot faster I’ve done no troubleshooting beyond getting it to this basic bit. I can’t remember why the “Optional.*SEARCHTERM” I know what it does(Should be search and with) and I know removing it causes unexpected results, and doesn’t just return Opt - search term.