Sponsored Content
Top Forums Shell Programming and Scripting Omitting sections of file that contain word Post 302709021 by SkySmart on Tuesday 2nd of October 2012 02:13:26 PM
Old 10-02-2012
Quote:
Originally Posted by Corona688
Code:
awk -v RS="" -v ORS="\n\n" -F"\n" '{ P=0
        for(N=1; N<=NF; N++) if($N ~ /host(group)?_name[ \t]+[^ \t]/) P=1 } P' inputfile


i'm sorry. when i said:

Code:
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?

thank you!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

omitting lines from file A that are in file B

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)
Discussion started by: gneen
14 Replies

2. UNIX for Advanced & Expert Users

extract multiple sections of a file

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)
Discussion started by: rgentis
1 Replies

3. Shell Programming and Scripting

extract multiple sections of file

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)
Discussion started by: rgentis
6 Replies

4. Shell Programming and Scripting

Best way to remove sections of text from a file

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)
Discussion started by: cals64
8 Replies

5. Shell Programming and Scripting

Parsing file, yaml file? Extracting specific sections

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)
Discussion started by: Rhije
3 Replies

6. Shell Programming and Scripting

Remove sections of a xml file with sed

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)
Discussion started by: viniciusandre
5 Replies

7. Shell Programming and Scripting

Modify sections of the line in a file

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)
Discussion started by: chiru_h
4 Replies

8. Shell Programming and Scripting

How to edit file sections that cross multiple lines?

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)
Discussion started by: Narnie
8 Replies

9. Programming

extract different sections of a file

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)
Discussion started by: raghu_shekar
1 Replies

10. Shell Programming and Scripting

awk removing sections of a file

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)
Discussion started by: BeefStu
5 Replies
HTML::Diff(3pm) 					User Contributed Perl Documentation					   HTML::Diff(3pm)

NAME
HTML::Diff - compare two strings of HTML This module compares two strings of HTML and returns a list of a chunks which indicate the diff between the two input strings, where changes in formatting are considered changes. HTML::Diff does not strictly parse the HTML. Instead, it uses regular expressions to make a decent effort at understanding the given HTML. As a result, there are many valid HTML documents for which it will not produce the correct answer. But there may be some invalid HTML documents for which it gives you the answer you're looking for. Your mileage may vary; test it on lots of inputs from your domain before relying on it. SYNOPSIS
$result = html_word_diff($left_text, $right_text); DESCRIPTION
Returns a reference to a list of triples [<flag>, <left>, <right>]. Each triple represents a check of the input texts. The flag tells you whether it represents a deletion, insertion, a modification, or an unchanged chunk. Every character of each input text is accounted for by some triple in the output. Specifically, Concatenating all the <left> members from the return value should produce $left_text, and likewise the <right> members concatenate together to produce $right_text. The <flag> is either 'u', '+', '-', or 'c', indicating whether the two chunks are the same, the $right_text contained this chunk and the left chunk didn't, or vice versa, or the two chunks are simply different. This follows the usage of Algorithm::Diff. The difference is computed on a word-by-word basis, "breaking" on visible words in the HTML text. If a tag only is changed, it will not be returned as an independent chunk but will be shown as a change to one of the neighboring words. For balanced tags, such as <b> </b>, it is intended that a change to the tag will be treated as a change to all words in between. AUTHOR
Whipped up by Ezra elias kilty Cooper, <ezra@ezrakilty.net>. Patch contributed by Adam <asjo@koldfront.dk>. SEE ALSO
Algorithm::Diff perl v5.14.2 2012-01-01 HTML::Diff(3pm)
All times are GMT -4. The time now is 02:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy