Sponsored Content
Full Discussion: replacing multiple lines
Top Forums Shell Programming and Scripting replacing multiple lines Post 19337 by Jimbo on Tuesday 9th of April 2002 06:55:15 PM
Old 04-09-2002
The awk solution below first stores the low-high file into an array.
As it passes and prints the main file, it notes which "POINT_NAME" is passing by. As LOW_ALARM and HIGH_ALARM lines go by, awk rebuilds those lines if values for that POINT_NAME are in the array.

The BEGIN processing stores the low-high file using default white-space field separation. But it then sets the Field Separator to a double-quote sign for processing of the main file because it makes the coding cleaner and more precise. With this field separator, each tag and each value become a separate field, and thus a little cleaner to identify.

Just for testing, I add (UPD) to the end of lines that I rebuild. I do not test to see if the value actually changes, so the (UPD) just means that I rebuilt the line with a value from the low-high file, even though the value could have remained the same.

I did not rely on POINT_NAME always being the nth word in that header line. I scan the line to isolate it.
Code:
#!/bin/sh
awk 'BEGIN {
  rc=getline < "ajnabi.lohi"
  while (rc==1)
     {lo[$1]=$2
      hi[$1]=$3
      rc=getline < "ajnabi.lohi"}
  FS="\""
}
{ if ($1$2=="OBJECT=POINT")
    for (i=3;i<=NF;i++)
       if (match($i,"POINT_NAME="))
          {pname=$(i+1)
           gsub(" ","",pname)}
  if ($1=="LOW_ALARM_LIMIT_1_VALUE=")
     if (pname in lo)
        $0="LOW_ALARM_LIMIT_1_VALUE=\"" lo[pname] "\""  " (CHG)"
  if ($1=="HIGH_ALARM_LIMIT_1_VALUE=")
     if (pname in hi)
        $0="HIGH_ALARM_LIMIT_1_VALUE=\"" hi[pname] "\""  " (CHG)"
  print
}' ajnabi.txt > ajnabi.txtNEW
exit 0


Last edited by Jimbo; 04-11-2002 at 09:11 AM..
Jimbo
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replacing multiple lines with single line

Can any one give me the idea on replacing multiple blank lines with a single blank line? Please conside it for a file having more than 100 number of characters. Regards, Siba (3 Replies)
Discussion started by: siba.s.nayak
3 Replies

2. Shell Programming and Scripting

replacing a quote in some lines with multiple quote fields

i want to replace mistaken quotes in line starting with tag 300 and relocate the quote in the correct position so the input is 223;25 224;20100428064823;1;0;0;0;0;0;0;0;8;1;3;9697;18744;;;;;;;;;;;; 300;X;Event:... (3 Replies)
Discussion started by: wradwan
3 Replies

3. Shell Programming and Scripting

Replacing pattern spanning multiple lines

Hi. I have input like this: <tr> <td class="logo1" rowspan="2"><a href="index.html"><img src="images/logo.png" /></a></td> <td class="pad1" rowspan="2">__</td> <td class="userBox"><img src="images/person.png"/> <a href="http://good.mybook.com/login.jsp">Sign In</a></td> <td... (5 Replies)
Discussion started by: zorrox
5 Replies

4. Shell Programming and Scripting

searching multiple lines and replacing in shell scripting

Hi, I have a file with below contents, ssenthil = rw anilkg = rw I want to search for "ssenthil" and need to delete line 1 and 2 , if the third line starts with "" respectively and blank line immediately and third line starts with " anilkg = rw Please help me . Great day... (5 Replies)
Discussion started by: anil8103
5 Replies

5. Shell Programming and Scripting

Replacing multiple lines in file from another file

Hi All, I'm trying to parse a XML file and replace few lines of file with text present in another file. But only issue is I need to replace only those lines from XML which are preceeding the JOBNAME =*RRN* For ex test.xml(content of XML file in which I want to replace lines is ) <JOB . . .... (10 Replies)
Discussion started by: techneel
10 Replies

6. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum using sed, awk

Hi friends, This is sed & awk type question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers whenever i find it and produce an output file with the sum. For example ###start of input text file #### abc def ghi 1 2 3 4 kjld random... (3 Replies)
Discussion started by: kaaliakahn
3 Replies

7. Shell Programming and Scripting

Replacing System.out.println with Logger.println in *.java using SED (spanned over multiple lines)

Hi, Can anyone help me out for my below problem. I need to replace all System.out.println with Logger.println in *.java using SED (spanning multiple lines) including current & sub-directories. I tried with below command. But it is not replacing when source text is spanned over multiple... (4 Replies)
Discussion started by: Bhanu Dhulipudi
4 Replies

8. Shell Programming and Scripting

Bash Scripting Help to automate replacing multiple lines

Background: I am writing a script to help me automate tweaks and things I apply to a custom Android rom I developed. I am on the very last part of my script, and I am stuck trying to find the right command to do what I seek. When I build roms from source, a file called updater-script is... (8 Replies)
Discussion started by: Silverlink34
8 Replies

9. Shell Programming and Scripting

Replacing a single line with multiple lines in a file

Hi Am confused with the usage of "sed" command I want to replace a single line with multiple lines of a file.. eg., A file has Hi, How are you? I need to replace as Am fine What are You doing? I used the script as string1="Hi, How are you?" echo "$string1 is the value"... (4 Replies)
Discussion started by: Priya Amaresh
4 Replies

10. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies
odbcinst(1)						       unixODBC manual pages						       odbcinst(1)

NAME
odbcinst - An unixODBC tool for manipulating configuration files SYNOPSIS
odbcinst ACTION OBJECT OPTIONS DESCRIPTION
odbcinst is a command line tool which has been created for allowing people who are developing the install scripts/RPMs for Drivers to be able to easily create/remove entries in odbc.ini and odbcinst.ini. This command line tool is a complement to the shared library of the same name (libodbcinst.so). This tool is a part of the odbcinst component of unixODBC. OPTIONS
ACTIONS -i Install (add section to config file) new OBJECT. -u Uninstall (remove section from config file) existing OBJECT. -q Query the config files and print the options for specified OBJECT. -j Prints current configuration of unixODBC, listing (among others) the paths to the configuration files. -c Calls SQLCreateDataSource -m Calls SQLManageDataSources --version Prints program version and exits. OBJECTS -d The ACTION affect drivers (and thus the odbcinst.ini configuration file). -s The ACTION affect data sources (and thus the user or system odbc.ini configuration file). OPTIONS -f FILE The FILE is template file, describing the configuration of installed OBJECT (only valid for the -i ACTION). -r Same as the -f OPTION, only take the standard input as the template file. -n NAME Specifies the NAME of the OBJECT. -v Turn off verbose mode. This turns off all information, warning and error messages. -l The specified data source is system-wide. Has any effect only with the -s OBJECT. -h The specified data source is user-specific. Has any effect only with the -s OBJECT. RETURN VALUES
This command returns zero on success and non-zero value on failure. FILES
/etc/odbinst.ini Configuration file containing all the database drivers specifications. See odbcinst.ini(5) for more details. /etc/odbc.ini System-wide data sources specifications. See odbc.ini(5) for more details. $HOME/.odbc.ini User-specific data sources specifications. See odbc.ini(5) for more details. SEE ALSO
odbcinst.ini(5), odbc.ini(5) AUTHORS
The authors of unixODBC are Peter Harvey <pharvey@codebydesign.com> and Nick Gorham <nick@easysoft.com>. For the full list of contributors see the AUTHORS file. COPYRIGHT
unixODBC is licensed under the GNU Lesser General Public License. For details about the license, see the COPYING file. version 2.3.1 Wed 26 Jun 2013 odbcinst(1)
All times are GMT -4. The time now is 10:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy