Siduction Forum

Siduction Forum => Scripting & Kernelhacking => Topic started by: michaa7 on 2013/05/31, 13:54:18

Title: grep Replaces (and show result *with* filename)
Post by: michaa7 on 2013/05/31, 13:54:18
I try to figure out whether some (texlive) packages had become obsolete or aren't built yet (the situation now lasts about a week). In the first case I can let them go, in the second case I can't.

I thought I could grep for "Replace" in the output of "apt-cache show texlive*"
Code: [Select]
apt-cache show texlive* | grep Replaces:
which actually shows that those files are *replaced*.
Unfortunately it does not show which package is the one which replaces some other one. And as "texlive*" covers more than the installed files I don't know which packages I need to install.

The flag "-H" should show the files name, but actually it shows "Standardeingabe" (I think this is "stdin") for all matches (probably due to the fact that the input is piped).

Does anybody has a clue how to extend the "code" such that it provides the name of the file/package which replaces "whatever".
Title: RE: grep Replaces (and show result *with* filename)
Post by: xaos52 on 2013/06/03, 12:36:27
You must escape the '*'
So use
Code: [Select]
apt-cache show 'texlive*' | grep Replaces
or
Code: [Select]
apt-cache show texlive\* | grep Replaces

To capture the name of the package you will probably have to resort to 'awk'.
Title: RE: grep Replaces (and show result *with* filename)
Post by: michaa7 on 2013/06/03, 13:17:16
Thanks!

Escaping might be the syntacticly clean version, but there is no difference in output no matter whether I escape or not.

As to 'awk', I'm *afraid* you are right, because it's japanees to me. I am completely lost with it.
Title: RE: grep Replaces (and show result *with* filename)
Post by: xaos52 on 2013/06/03, 18:08:55
Code: [Select]
{
    if ( $0 ~ /Package:/ ) { package=$0 }
    if ( $0 ~ /Replaces:/ ) { printf "%s %s\n\n",package,$0 }
}
save this somewhere.
Then run
Code: [Select]
apt-cache show texlive\* | awk -f <path-to-the-awk-script>
Title: RE: grep Replaces (and show result *with* filename)
Post by: michaa7 on 2013/06/04, 21:54:34
Thanks!

Meanwhile I solved this in an other way:

Code: [Select]
# apt-cache show texlive* | egrep "^Package|Replaces" | grep "Replaces" -B1

Not really elegant, but at my level of knowledge ;-) .

From what I read so far I feel awk would be a blind alley for me.
Do you know by chance an appropriate, but free manual for shell scripting for absolut beginners? The ones I found googeling did not explain at the right level. I need something explaining basics only (variables, loops), something for fools, something where I may have success with little steps?
Title: RE: grep Replaces (and show result *with* filename)
Post by: Geier0815 on 2013/06/04, 22:26:54
THIS (http://tldp.org/LDP/abs/html/index.html) is the best guide thru bash. The problem is that bash is not as easy as it seems...
Title: RE: grep Replaces (and show result *with* filename)
Post by: michaa7 on 2013/06/04, 22:58:28
Thanks Geier0815.
I have now doubt it's the best ... for you. I will bookmarkt it and give it a try. Still, I'd like to find something for me where neither the first word is "Advanced" nor it actually being written for advanced users ...

I now give thisone a try and we'll see where it leads ...
http://tldp.org/LDP/Bash-Beginners-Guide/html/