You are not logged in.
Pages: 1
Let's say we got this string xfce4-clipman-plugin-0.4.1
I want to cut it to output xfce4-clipman-plugin
how i can do that?
cut -d - f1 outputs xfce4
Is there any way to tell cut to cut it at third dash?
Favorite systems: ArchLinux, OpenBSD
"Yes, I love UNIX"
Offline
$ echo "xfce4-clipman-plugin-0.4.1" | cut -d '-' -f"1,2,3"
xfce4-clipman-plugin
If you specify more than one field, it'll print out more than one.
Offline
Cerebral, but here we got another problem
xfce4-0.4.1 with your solution outputs xfce4-0.4.1 instead of just xfce4
I would like to output only the base name of the package regardless of the number of dashes inside it.
Favorite systems: ArchLinux, OpenBSD
"Yes, I love UNIX"
Offline
Not elagant, but it works:
pacman -Q | cut -d" " -f1 | cut -d"-" -f1
Offline
but is it possible to do that without using pacman, just plain old unix tools... cut, sed, paste
Favorite systems: ArchLinux, OpenBSD
"Yes, I love UNIX"
Offline
ah, using sed, sure:
$ echo "xfce4-clipman-plugin-0.4.1" | sed "s/(.*)-.*/1/g"
xfce4-clipman-plugin
Offline
ah, using sed, sure:
$ echo "xfce4-clipman-plugin-0.4.1" | sed "s/(.*)-.*/1/g" xfce4-clipman-plugin
Cerebral, thanks sed is great
any chance to do the same only with 'cut'?
Favorite systems: ArchLinux, OpenBSD
"Yes, I love UNIX"
Offline
Pretty sure it's not possible just with cut.
I am a gated community.
Offline
but is it possible to do that without using pacman, just plain old unix tools... cut, sed, paste
You don't need pacman, it was just an example to make sure it works.
You could always:
echo "xfce4-some-package 0.4.1" | cut -d" " -f1 | cut -d"-" -f1
Offline
Pretty sure it's not possible just with cut.
Sure it is, check out what iBertus posted:
echo "xfce4-some-package 0.4.1" | cut -d" " -f1 | cut -d"-" -f1
you can also:
echo "xfce4-some-package 0.4.1" | tr ' ' '-' | cut -d'-' -f1
Offline
you can also:
echo "xfce4-some-package 0.4.1" | tr ' ' '-' | cut -d'-' -f1
That does _not_ work:
$ echo "xfce4-some-package 0.4.1" | tr ' ' '-' | cut -d'-' -f1
xfce4
It only prints the first field.
Offline
Ahhh, i thought he wanted just the first word...
I'd use sed... though, you may want to take $pkgrel into account:
echo "xfce4-clipman-plugin-0.4.1-1" | sed "s|(.*)-.*-.*|1|g"
Offline
Let's say we got this string xfce4-clipman-plugin-0.4.1
I want to cut it to output xfce4-clipman-plugin
how i can do that?
cut -d - f1 outputs xfce4
Is there any way to tell cut to cut it at third dash?
echo foo-ooo-bar-345 | cut -d '-' -f 1-3
will give you
foo-ooo-bar
Is that what you want?
Offline
pixel wrote:Let's say we got this string xfce4-clipman-plugin-0.4.1
I want to cut it to output xfce4-clipman-plugin
how i can do that?
cut -d - f1 outputs xfce4
Is there any way to tell cut to cut it at third dash?echo foo-ooo-bar-345 | cut -d '-' -f 1-3
will give you
foo-ooo-bar
Is that what you want?
That wont work for all packages. You are splitting at the `-' and printing only the first to third instances of it and not all package names will have three hyphens.
Phrakture's solution is the best. Its saying take the whole field, not anything and anything with -* and -* (pkgver, pkgrel) and print the first field which was the 'not anything' field, or pkgname.
Offline
It always irritated me that you cannot tell cut to count from the end; "give me the second last field" or "give me all fields up to the third last". It should have had that feature.
All of your mips are belong to us!!
Offline
It always irritated me that you cannot tell cut to count from the end; "give me the second last field" or "give me all fields up to the third last". It should have had that feature.
python -c "print 'one two three four'.split(' ')[-2]"
python -c "print 'one two three four'.split(' ')[:-3]"
Offline
Yes, I'm aware that scripting languages usually have that kind of indexing/slicing - cut most definitely should have had it - this is all it does dammit, why doesn't it do it properly?
All of your mips are belong to us!!
Offline
echo 'one two three four' | awk '{print $(NF-2),$(NF-1),$NF}'
Offline
what? this is a contest or something
KISS = "It can scarcely be denied that the supreme goal of all theory is to make the irreducible basic elements as simple and as few as possible without having to surrender the adequate representation of a single datum of experience." - Albert Einstein
Offline
Pages: 1