You are not logged in.

#1 2012-02-16 06:31:40

Bellum
Member
Registered: 2011-08-24
Posts: 230

fex - Flexible field/token extraction

So I was writing some sh script, and I wanted to to grab some token offset from the end of a line delimited by a give character. I was trying to figure out how to do this using the standard tools, and I stumbled upon a profound and simple truth: some of these tools are a pain in the ass!

I set out to write a tool to do the job myself, but it turns out someone's beaten me to the punch! Enter fex.

example:

$ echo one/two/three/four/five | fex 0/{1,2,3,-2,-1}
one two three four five

Does one thing and does it well. What a concept! :P

Grab the pkgbuild.

Offline

#2 2012-02-16 07:07:57

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: fex - Flexible field/token extraction

That'll be fun:

[karol@black ~]$ echo one/two/three/four/five | tr '/' ' '
one two three four five

It's a new "Hello world!" test :-)

[karol@black ~]$ echo one/two/three/four/five | cut -d'/' --output-delimiter=' ' -f1-5
one two three four five

fex is a pretty neat app, but I'm not convinced that the standard tools are insufficient.

Last edited by karol (2012-02-16 07:27:55)

Offline

#3 2012-02-16 07:22:38

Bellum
Member
Registered: 2011-08-24
Posts: 230

Re: fex - Flexible field/token extraction

$ echo one/two/three/four/five | sed 's:/: :g'
one two three four five

:D

Offline

#4 2012-02-16 14:03:11

Bellum
Member
Registered: 2011-08-24
Posts: 230

Re: fex - Flexible field/token extraction

fex is a pretty neat app, but I'm not convinced that the standard tools are insufficient.

I didn't say they were insufficient, I said they were a pain in the ass, more so for this particular purpose than they need to be.

Cut and fex solve similar problems, but cut cannot offset from the end of a line, a pretty big oversight (plus fex is nicer.). tr and sed are solving completely different problems in these examples. I'm sure we can some up with a million ways to replace slashes with spaces in unix. That they have the same effect in this example is a coincidence, and that wont be the case for variable inputs. I don't doubt it's possible (I know for a fact that it is),  but I couldn't figure it out. One day I'll sit down and dedicate the whole day to learning awk. Scouts honor. :P

Offline

Board footer

Powered by FluxBB