Home / Software / BSD, Linux, and Unix / sed command
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] - (Bottom) Print
Author Topic: sed command  (Read 295 times)
skillmurt
Topic Starter
Newbie



Posts: 1

Experience: Beginner
OS: Unknown

« on: September 12, 2011, 08:06:09 AM »

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!

Roger
IP logged
ghostdog74
Mentor



Thanked: 26
Posts: 1,511


« Reply #1 on: September 12, 2011, 07:30:39 PM »

You use awk, not sed

Code: [Select]

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

IP logged

Pages: [1] - (Top) Print 
Home / Software / BSD, Linux, and Unix / sed command « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.097 seconds with 20 queries.