anyway to mimick a regular expression or sed?

   5803   11   1
User Avatar
Member
176 posts
Joined: July 2005
Offline
just wondering if there is a way to duplicate this unix command in hscript or an expression function

pwd|sed -e “s/\// /g”

this is taking the “/” and replacing it with a space

if pwd was /volumes/c/hello
it would return:

volumes c hello


more simple ex: sed -e “s/hello/goodbye/g”
that would replace hello with goodbye

wondering if there is something similar to this in expression functions or hscript

I saw the opreplace but that is just for operator names…I'm looking to be able to split up the paths and then use the arg function on them…

thanks in advance for any help!
:shock:
User Avatar
Member
8080 posts
Joined: July 2005
Offline
what about strreplace?
User Avatar
Member
176 posts
Joined: July 2005
Offline
sweet! thanks Edward!
User Avatar
Member
7046 posts
Joined: July 2005
Offline
You can always call sed using the system() expression, with lots of tedious escaping of quotes and so forth.

Antoine at R+H wrote a bunch of custom functions that wrap sed, perl etc (mostly perl) so that you can avoid the tedious escaping most of the time.

Cheers,

Peter B
Cheers,

Peter Bowmar
____________
Houdini 20.5.262 Win 10 Py 3.11
User Avatar
Member
176 posts
Joined: July 2005
Offline
So how exactly could you pipe something into sed using the system exp?

normally I would think of

pwd|sed -e “s/string/replace/g”

so when in houdini

set var = pwd|`system(“sed -e \”s/string/replace/g\“”)`
echo var

what would be the method of getting it to work?

and does the pipe work the same in houdini (“|”) ???
User Avatar
Member
8080 posts
Joined: July 2005
Offline
There's no pipes in Houdini. You can do something like:
strreplace(system(“pwd”),“/”,“ ”)

Or use the upwd command: strreplace(run(“upwd”),“/”,“ ”)
User Avatar
Member
176 posts
Joined: July 2005
Offline
Yeah I was able to get the strreplace to work for sure…
I am still interested in what Peter said just to know how to do it…

not that it would be as efficient as strreplace…but it would be nice to know both…

thats too bad there are no pipes… :?
User Avatar
Member
176 posts
Joined: July 2005
Offline
is the workaround for pipes a multi-step process?

pwd > file
set var = echo `system(“cat file”)`
set nvar = `somefunction($var)`
echo $nvar

or

set var = echo `system(“pwd”)`
set nvar = `somefunction($var)`
echo $nvar
User Avatar
Member
639 posts
Joined: July 2005
Offline
Hey Lynch,

I tried using the pipe to send stuff out, looks like Hscript can't do it. Then again, I hardly every try to use HScript to do complex processing… Typically when I have to deal with patterns, I'd resort of Perl or Python and have it talk to Houdini instead via a socket. It probably is an overhead this way, but it is machine time as opposed to our time.

-Alex
User Avatar
Member
176 posts
Joined: July 2005
Offline
I definetly agree that something like this should be done in a more powerful language….but does anyone know how to do what Peter was talking about?

meaning the proper syntax for sending it into an actual sed in unix from houdini?
User Avatar
Member
7046 posts
Joined: July 2005
Offline
Hey,
Assuming strreplace() wasn't available (which it wasn't until H8) here's what you could do

/ -> set dir = `system(“pwd”)`
/ -> set newdir = `system(“echo $dir | sed -e \”s/\// /g\“”)`

Note that I have to escape the quotes in the sed string, making it more cumbersome than it should be.

However, if you did this a lot you could wrap that system() call in a custom Hscript function to avoid all the unpleasant escaping.

At R+H, they do lots of this type of thing with single line Perl calls, for example.

This should also work on Windows if you have the Cygwin package installed. I did a whole pipeline on Windows once, and this stuff worked fine with Cygwin.

Cheers,

Peter B
Cheers,

Peter Bowmar
____________
Houdini 20.5.262 Win 10 Py 3.11
User Avatar
Member
176 posts
Joined: July 2005
Offline
thanks man! I actually am running cygwin on windows and fedora core 4….so I am happy either way…

I just could't wrap my head around the idea how to pipe it into the sed…but setting the variable first should have been obvious….

yeah agreed you could make a function out of this and use args to handle the input…that would be a great idea.

My next feat is to learn perl for sure…just got into the word of programming somewhat recently and have found most of my time using unix and hscript. I've heard perl is quick and dirty…sounds fun. :wink:
  • Quick Links