I have a configuration file that contains hundreds of these chunks. Each "chunk" is the section that begins with "define service {" and ends with "}".
Now, let's assume the above configuration is from a file called process.cfg.
Now, what I wish to do is to "cat" the process.cfg file, and then omit every chunk in that file that has nothing set for the "hostgroup_name". Then redirect results to a new file. this new file which will be void of the chunks that do not have anything set for hostgroup_name.
There is a challenge to this.
If you look at each chunk above, you will see that all of them have nothing set for "hostgroup_name". So if i cat the process.cfg and I run an awk code against it, what would be left will be, most likely, the last chunk.
If you look at the very last chunk, you see that, there are hosts set up for it. the "host_name" section has hosts defined. so, in this case, i dont want this chunk to be omitted. i would ever like to have it ommitted if the host_name field exist, AND is also empty as well.
os: linux
shell: bash
sample of a code that can be modified to do the above:
the "/tmp/listofhosts.txt" may not be necessary. but i dont know how to make this code woork.
That is a useless use of cat. awk, or any other shell command, does not need cat's help to read a single file.
If you set awk's record separator to blank, it will take blank lines to be the separators between records here:
this seems to work marvelously. the problem is, it also removes chunks that has "host_name".
if the code you provided finds a section that looks something like this:
i want it to only delete the line that has the "hostgroup_name" on it. meaning, if hostgroup_name is empty, but the host_name is not, then, delete line containing hostgroup_name and still output the chunk (but with the hostgroup_name line deleted).
however, if both hostgroup_name AND host_name are empty, then OMIT the entire chunk.
there will be chunks where "hostgroup_name" is defined, but "host_name" is not. and vice versa.
i meant to say, while there are some chunks where hostgroup_name is defined, but "host_name" is not, and vice versa, there are also some chunks where neither are present. meaning, there are junks where lines for "host_name" and "hostgroup_name" do not exist.
so this code u just pasted didn't take that into account. in the final file that was outputted, those chunks were removed (the chunks that did not have lines with the word hostgroup_name OR host_name on them). i dont want that.
i'm very sorry for the confusion. can you please modify your code to take that into account?
I have a file that looks liek this (see below). can somebody provide me with and awk or sed command that can take a piece of the file starting from the time to the blank line and put in into another file.
For example: How would I get the data from 10:56:11 to the blank line.
Two things:
... (5 Replies)
Hi All,
I have a file with the data 10;20;30;40;50;60;70;80;123;145;156;345. the output i want is the first fourth sixth elements and everything from there on. How do i achieve this. (1 Reply)
Hello,
I'm wondering where I could go to learn how to edit file sections that cross multiple lines. I'm wanting to write scripts that will add Gnome menu entries for all users on a system for scripts I write, etc. I can search an replace simple examples with sed, but this seems more complex.
... (8 Replies)
Hello..
I have a line in a file which I have to edit:
the line looks like:
<!]>
Sometimes, the section of the line can have only one entry for cn, or maybe more than 2 like below:
<!]>
I have a variable which has the following value:
CN="(cn=MNO)(cn=XYZ)"
I need to replace the part... (4 Replies)
I've been trying to remove some lines of a xml file that looks like this:
<parent>
<child>name1</child>
<lots_of_other tags></lots_of_other_tags>
</parent>
<parent>
<child>name2</child>
<lots_of_other tags></lots_of_other_tags>
</parent>
<parent>
<child>name3</child>
... (5 Replies)
Here is a data file, which I believe is in YAML. I am trying to retrieve just the 'addon_domains" section, which doesnt seem to be as easy as I had originally thought. Any help on this would be greatly appreciated!! I have been trying to do this in awk and mostly bash scripting instead of perl... (3 Replies)
Greetings! I found this fourm via a google search on "sed expressions".
I have a file that contains notices and they are all the same length in lines. For example the file would contains 15 notices, each being 26 lines each. I need some way to eliminate notices that contain a "S" in a particular... (8 Replies)
I have a file that I need to parse multiple sections from the file.
The file contains multiple lines that start with ST (Abunch of data)
Then the file contains multiple lines that start with SE (Abunch of data)
SE*30*0001
ST*810*0002
I need all of the lines between and including these.... (6 Replies)
I have a file that I need to parse multiple sections from the file.
The file contains multiple lines that start with ST (Abunch of data)
Then the file contains multiple lines that start with SE (Abunch of data)
SE*30*0001 ... (1 Reply)
I've got file A with (say) 1M lines in it ... ascii text, space delimited ...
I've got file B with (say) 10M lines in it ... same structure.
I want to remove any lines from A that appear (identically) in B and print the remaining (say) 900K lines. (And I want to do it in zero time of... (14 Replies)