You are not logged in.
Pages: 1
Hello,
I have a simple problem
I'm searching after the pkgver in the PKGBUILD file.
No problem: cat PKGBUILD | grep 'pkgver='
For example I get: 'pkgver=2.6.23.8'
But I only want the string '2.6.23.8'
I tested tail, head, basename and sed (complex) but I couldn't find any solution.
I think there must be a simple solution
Thanks for help!
Best regards,
Flasher
Offline
I think there must be a simple solution
A few ways. Try this:
echo pkgver=2.6.23.8 | cut -d= -f2
Offline
You can use cut to break it at the equals sign and then take the second field.
cat PKGBUILD | grep pkgver= | cut -d = -f 2
Offline
grep ^pkgver= PKGBUILD | cut -d= -f2
awk -F = '/^pkgver=/ { print $2 };' PKGBUILD
1000
Offline
Offtopic, but I have to point out the useless use of cat - do this instead:
grep pkgver= PKGBUILD | ...
Offline
Offtopic, but I have to point out the useless use of cat - do this instead:
grep pkgver= PKGBUILD | ...
Here ya go:
Offline
One-liner in sed (don't even need to use grep!):
$ sed -n "/pkgver=/ { s/pkgver=//; p }" PKGBUILD
^ ^ ^ ^ Tells sed to print the line
^ ^ ^ This part strips out pkgver=
^ ^This part does the grep for you
^ This part tells sed to print nothing unless told
Last edited by Cerebral (2007-12-03 03:41:13)
Offline
Another sed version:
sed -n "s/^pkgver=\(.*\)$/\1/p" PKGBUILD
Or you can do
. PKGBUILD
and then just use $pkgver directly
Offline
Or you can do . PKGBUILD and then just use $pkgver directly
And what about "rm -rf /" somewhere in PKGBUILD ? (;
grep -Po "(?<=^pkgver=)(\d+\.?)+" PKGBUILD
Last edited by elide (2007-12-03 07:48:44)
Offline
Another sed version:
sed -n "s/^pkgver=\(.*\)$/\1/p" PKGBUILD
Actually, you don't need to bother with storing the result:
sed -n "s/^pkgver=//p" PKGBUILD
works, and is simpler.
Offline
@Cerebral: Gah, yes, of course I'm usually using sed to a bit more complex patterns, so it didn't strike me that I could do it simpler
Offline
@Cerebral: Gah, yes, of course I'm usually using sed to a bit more complex patterns, so it didn't strike me that I could do it simpler
lol - same here. Take a look at my first version - totally more complex than necessary. XD
Offline
Pages: 1