1

I'm a student from indonesia and I want to create an script that deletes few lines from a file containing the following text:

zone "irf.com" {
type master;
file "db.irf.com";
allow-update { none; };
};

zone "friedrice.com" {
type master;
file "db.friedrice.com";
allow-update { none; };
};

zone "you.com" {
type master;
file "db.you.com";
allow-update { none; };
};

If i want to delete this:

zone "friedrice.com" {
type master;
file "db.friedrice.com";
allow-update { none; };
};

In the terminal I can run: sh you.txt friedrice

How is the syntax in shell programming??

All the text is in a file, let's say you.txt

I'm a newbie, so please help me

Luis Quijada
  • 2,345
  • 1
  • 26
  • 31
achmad irfan
  • 55
  • 1
  • 1
  • 7
  • 1
    Please.. don't name your config or script files `*.txt`... – ThiefMaster Jul 01 '12 at 10:46
  • While you have received some good answers to your concrete question, they amount to using unstructured tools to manipulate structured data. You have zone data, not XML, but that's a detail; this is fundamentally the same problem as http://stackoverflow.com/questions/701166/can-you-provide-some-examples-of-why-it-is-hard-to-parse-xml-and-html-with-a-reg – tripleee Jul 01 '12 at 10:49

2 Answers2

0

Use this:

sed -i -E -n '1h;1!H;${;g;s/zone "friedrice.com" {[^}]*};\n};//g;p;}' you.txt
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
mVChr
  • 49,587
  • 11
  • 107
  • 104
0
sed -i '/^zone "friedrice.com"/,/^}/d' you.txt
Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439