CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (http://www.cfd-online.com/Forums/openfoam-solving/)
-   -   script for replacing block of code (http://www.cfd-online.com/Forums/openfoam-solving/114637-script-replacing-block-code.html)

Henning86 March 14, 2013 12:18

script for replacing block of code
 
Im runnning OpenFoam on a server. im exchanging the data with samba and do the post processing with paraview on windows the problem is that paraview doesn't know the bc:

Code:

inflow
{
type uniformFixedValue;
uniformValue table
(
( 0 (0 0 0.0))
( 0.0005 (50 0 0.0))
( 0.0025(600 0 0))
);
}

so i can't see the velocity field. I want to replace the solution with a different BC for example

Code:

inflow
{
type fixedValue;
value uniform (600 0 0);
}

With that bc im able to see the the velocity field with paraview on the local windows machine.

I am looking for a script that is able to replace the whole String block with another one

I just manage do replace a string with a script in the subfolder my code for that is (which works but doesn't solve the problem):

Code:

#!/bin/bash
find . -name "*.txt" -exec sed -i 's/old/new/g' {} \;

Im unable to find a sed code that will do the job.

Can anybody post a script that will replace the bc with the other one?

Nucleophobe March 14, 2013 12:48

In vim, you *can* do multiline find-replace. Just use '\n' to capture newlines.

There's probably a better way, as this gets messy. But you can try:

Code:

:%s/inflow\n{\ntype uniformFixedValue; \nuniformValue table \n(\n( 0 (0 0 0.0))\n( 0.0005 (50 0 0.0)) \n( 0.0025(600 0 0)) \n);\n}/inflow\r{\rtype fixedValue;\rvalue uniform (600 0 0);\r}
The '\r' is also a carriage return. I don't understand why, but if you try to write the '\n' character, it turns into '\@'

Anyways, I just tried this and it worked.

Henning86 March 15, 2013 05:32

im really bad at scripting. so i just replaced sed with vim.tiny followed by the long command:

Code:

#!/bin/bash
find . -name "*.jsp" -exec vim.tiny :%s/inflow\n{\ntype uniformFixedValue; \nuniformValue table \n(\n( 0 (0 0 0.0))\n( 0.0005 (50 0 0.0)) \n( 0.0025(600 0 0)) \n);\n}/inflow\r{\rtype fixedValue;\rvalue uniform (600 0 0);\r}

This gives me an error.

Can vim be used in a script and is vim.tiny able to do that?

vim isn't installed at the server.

i sadly haven't worked with vim at all.


All times are GMT -4. The time now is 00:46.