1.

Solve : sed command?

Answer»

Hi EVERYBODY!

I want to change some lines of text with the sed command but not as usual. This are the lines I have:

south
{
type            zeroGradient;
}
WEST
{
type            zeroGradient;
}
east
{
type            zeroGradient;
}
NORTH
{
type            zeroGradient;
}
TOP
{
type            zeroGradient;
}
}


And these are the lines I want:

south
{
type            zeroGradient;
}
west
{
type            symmetryPlane;
}
east
{
type            symmetryPlane;
}
north
{
type            zeroGradient;
}
top
{
type            zeroGradient;
}
}

I'm working on CFD simulations and the number of lines depend on the grid... So I can't use: sed -i '22s/zeroGradient/symmetryPlane/g', because it won't be allways at the same line.

What can I do?

Thank you very much for helping me!

RogerYou use awk, not sed

Code: [Select]
awk -vRS="}" '/west|east/{ gsub(/zeroGradient/,"symmetryPlane"); }1' ORS="}" file



Discussion

No Comment Found