Replace pattern in files during package installation (e.g. using 'sed')

Background:
In some .xsl file downloaded via an own formula of a private tap I want to link to another xsl file installed from the homebrew-core repository.

Now I could just assume that that the default path to all installed packages is
/usr/local/Cellar/
and enter the path by hand into my .xsl file.

 <xsl:import href="/usr/local/Cellar/...

What I’d like to do though is take advantage of $HOMEBREW_CELLAR variable and do something like this:

 <xsl:import href="$HOMEBREW_CELLAR/...

Turns out though you can’t place bash variables inside .xsl files.

Question
Is there a way to replace a pattern in .xsl file (or any file) during installation via homebrew by executing for example a sed command?

Is there a way to replace a pattern in .xsl file (or any file) during installation via homebrew by executing for example a sed command?

Yes, I think searching for replace in homebrew-core will get you plenty of examples

1 Like

Instead of replacing with $HOMEBREW_PREFIX would it also be possible to use another package’s prefix value?
So that I’d get

#{HOMEBREW_PREFIX}/Cellar/#{name}/#{version}

#{Formula["something"]}.opt_bin

2 Likes

Once again, thank you for your help!

Though I did alter your suggested solution a bit and used this pattern as a replacement:

"#{Formula["foo"].prefix}"

which lead to the expected result, except…

… I expected to end up with a path looking something like this

/home/linuxbrew/.linuxbrew/Cellar/foo/

but instead got this:

/home/linuxbrew/.linuxbrew/opt/foo/

What is the opt directory about? It seems like this is a duplicate of what’s inside Cellar.

Also grepping into the homebrew-core repository got me some examples using #{Formula["foo"].opt_prefix
I expected .opt_prefixto lead me to to the ‘copy’ inside the /opt/ directory and therefore used just .prefix to land in the Cellar, but apparently I didn’t.

EDIT: Concerning the confusion about what the /opt/ directory is about I just found an answer here.