Sponsored Content
Full Discussion: awk script modification
Top Forums Shell Programming and Scripting awk script modification Post 302686691 by SkySmart on Wednesday 15th of August 2012 09:02:11 AM
Old 08-15-2012
awk script modification

I want the below script to omit every chunk of data that contains a specific hostname.

here's the scenario. i have a configuration file that contains the configuration of several hosts. a sample of this configuration file is this:


Code:
define host {
        address                       10.70.40.40
        host_name                     relay-nasty-01.net
        use                           generic-host
}

define host {
        address                       10.70.40.42
        host_name                     relay-nasty-02.net
        use                           generic-host
}

define host {
        address                       10.70.40.43
        host_name                     relay-nasty-03.net
        use                           generic-host
}

The above is the configuration for Three hosts: relay-nasty-01.net, relay-nasty-02.net, relay-nasty-03.net.

now, this configuration data is quite huge, since it contains information for several hosts.

now, i want to scan this configuration file against a list of host names. and if any of the hostname in this list is found in the configuration file, i want information about that host name to be omitted. I want a new configuration file created without the configuration for that host name(s).

so for example, if relay-nasty-02.net was in the list of hostnames i want to remove from the configuration file, i want a script that will scan the configuration and output EVERYTHING ELSE BUT the configuration for relay-nasty-02.net.

below is a script i was working on. but i dont know how to modify it to do what i specified above.

Code:
awk 'BEGIN {
  while((getline < "/tmp/host_list.txt")>0)
     S[$0]

  FS="\n"; RS="}\n"; ORS="}\n";
}

/define host/ {

  for(X in D) delete D[X];

  for(N=2; N<=NF; N++)
  {
       split($N, A, " ");
       D[A[1]]=A[2];
  }

  if (D["host_name"] in S)
       printf("%s -------- %s -------- %s\n", D["host_name"]" " " ", D["address"], D["_secondary_address"])

}' /tmp/hosts.conf

so basically, i would like to modify this script to make it so, when i scan it against the configuration file, it will omit the configuration setup of the host(s) in the list i give it.

so in my example, if i run this script, it should only output the below, because relay-nasty-02.net was in the list of hosts i gave it.

Code:
define host {
        address                       10.70.40.40
        host_name                     relay-nasty-01.net
        use                           generic-host
}


define host {
        address                       10.70.40.43
        host_name                     relay-nasty-03.net
        use                           generic-host
}

OS: linux/sun
shell: bash
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

help in script modification

i have the following perl script.but it searches for a given filename. i want to run the same script in my directoy which has subdirectories too and it has to display the file if sreach satisfies along with directory name. can anyone help me: perl script: my $FILE = $ARGV; for zf in... (4 Replies)
Discussion started by: a.suryakumar
4 Replies

2. Shell Programming and Scripting

Need a modification on this script

Hi All I have files contains rows which look like this: 2 20090721_16:58:47.173 JSUD2 JD1M1 20 IAM 966591835270 249918113182 b 3610 ACM b 3614 ACM b 3713 CPG b 3717 CPG f 5799 REL b 5815 RLC b 5817 RLC :COMMA: NCI=00,FCI=6101,CPC=0A,TMR=00,OFI=00,USI: :COMMB: BCI=1234: :RELCAUSE:10: ... (1 Reply)
Discussion started by: zanetti321
1 Replies

3. Shell Programming and Scripting

in line modification in a file using awk

Hi, I have a conf.file with the following values: ef=78 b=40 ca=40 c=45/dev2 when I modify one of the line with the below awk script,it's modifying BUT it's placing the modified line in the last line : input:- Configure b 45/dev4 output:- ef=78 ca=40 ... (2 Replies)
Discussion started by: axes
2 Replies

4. Shell Programming and Scripting

Awk modification

I need help modifying the code below. DATAFILE is a log file. I have two strings i need to search for in the log file. The two strings are: 1. ERROR 2. com.rolander.promotions.client awk 'BEGIN { while((getline < "'${SFILE}'")>0) S FS="\n"; RS="\n" } (11 Replies)
Discussion started by: SkySmart
11 Replies

5. Shell Programming and Scripting

awk modification for lines

so i have this data in a file: jime=1860,yime=1.23243,lime= jime=1859,yime=1.23018,lime= jime=1825,yime=1.15371,lime= jime=1849,yime=1.20769,lime= jime=1841,yime=1.1897,lime= jime=1849,yime=1.20769,lime= i use this code to calculate the percentage difference of the number in column 2... (9 Replies)
Discussion started by: SkySmart
9 Replies

6. UNIX for Dummies Questions & Answers

awk output modification

Hello, I am using awk command to print some output, but there are some characters that I would like to remove from the output awk '{print $5$6}' the output I get is column5/:column6 I am looking forward to remove the : and to get the output column5/column6 Sorry if this question is... (4 Replies)
Discussion started by: Error404
4 Replies

7. Shell Programming and Scripting

IP Address Modification through awk/sed

Hi, I have to modify the 2nd and 3rd octet of the IP address through awk/sed. For Example: Given IP is : 10.205.22.254, it should be modified as 10.105.100.254 through awk/sed. Kindly help me on this and let me know if you have any questions. Thanks in advances. (2 Replies)
Discussion started by: kumarbka
2 Replies

8. Shell Programming and Scripting

awk script modification - treat certain files differently

awk 'BEGIN{OFS=","} FNR == 1 {if (NR > 1) {print fn,fnr,nl} fn=FILENAME; fnr = 1; nl = 0} {fnr = FNR} /UNUSUAL/ && /\.gz/ ~ /FILENAME/ {nl++} <'{system ("gunzip -cd FILENAME")}' END ... (2 Replies)
Discussion started by: SkySmart
2 Replies

9. Shell Programming and Scripting

awk script modification

can someone help me identify what i'm doing wrong here: awk -F'|' 'BEGIN{c=0} /./ && /./ { if ($3 < 2) { print ; c++ } END { print c":OK" } else if (($3 >= 2) && ($3 < 4)) { print ; c++ } END { print c":WARNING" } else if ($3 >= 4) { print ; c++ } END { print c":CRITICAL" } }'... (4 Replies)
Discussion started by: SkySmart
4 Replies

10. Shell Programming and Scripting

Modification to awk command

i have a php file that has this: php.code #!/usr/bin/php <?php phpinfo(); hlight_file(__FILE__); ?> I want my awk code grab whatever is inbetween and including the "<?php" and "?>". Then, it should scan all the entries between these two points. And if the entries between these... (10 Replies)
Discussion started by: SkySmart
10 Replies
sane-net(5)							File Formats Manual						       sane-net(5)

NAME
sane-net - SANE network backend DESCRIPTION
The sane-net library implements a SANE (Scanner Access Now Easy) backend that provides access to image acquisition devices through a net- work connection. This makes it possible to control devices attached to a remote host and also provides a means to grant users access to protected resources. DEVICE NAMES
This backend expects device names of the form: host:device Where host is the name of the (remote-) host and device is the name of the device on this host that should be addressed. If the device name does not contain a colon (:), then the entire string is treated as the device string for the default host. The default host is the host listed last in the configuration file (see below). CONFIGURATION
The contents of the net.conf. file is a list of host names that should be contacted for scan requests. Empty lines and lines starting with a hash mark (#) are ignored. A sample configuration file is shown below: scan-server.somedomain.firm # this is a comment localhost The above list of host names can be extended at run-time using environment variable SANE_NET_HOSTS. This environment variable is a colon- separated list of hostnames that should be contacted in addition to the hosts mentioned in the configuration file. For example, a user could set the environment variable to the string: new.scanner.com:scanner.univ.edu To request that hosts new.scanner.com and scanner.univ.edu are contacted in addition to the hosts listed above. For this backend to function properly, it is also necessary to define the sane service in /etc/services. At present, the sane service should be defined using a line of the following form: sane 6566/tcp # SANE network scanner daemon FILES
/etc/sane.d/net.conf The backend configuration file (see also description of SANE_CONFIG_DIR below). /usr/lib/sane/libsane-net.a The static library implementing this backend. /usr/lib/sane/libsane-net.so The shared library implementing this backend (present on systems that support dynamic loading). ENVIRONMENT
SANE_CONFIG_DIR This environment variable specifies the list of directories that may contain the configuration file. Under UNIX, the directories are separated by a colon (`:'), under OS/2, they are separated by a semi-colon (`;'). If this variable is not set, the configura- tion file is searched in two default directories: first, the current working directory (".") and then in /etc/sane.d. If the value of the environment variable ends with the directory separator character, then the default directories are searched after the explic- itly specified directories. For example, setting SANE_CONFIG_DIR to "/tmp/config:" would result in directories "tmp/config", ".", and "/etc/sane.d" being searched (in this order). SANE_NET_HOSTS A colon-separated list of host names to be contacted by this backend. SANE_DEBUG_NET If the library was compiled with debug support enabled, this environment variable controls the debug level for this backend. E.g., a value of 128 requests all debug output to be printed. Smaller levels reduce verbosity. BUGS
If saned has timed out, the net backend may loop with authorization requests. SEE ALSO
sane(7), saned(1), sane-dll(5), scanimage(1) http://www.penguin-breeder.org/?page=sane-net AUTHOR
David Mosberger and Andreas Beck 8 Oct 2002 sane-net(5)
All times are GMT -4. The time now is 12:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy