Removing sections


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing sections
# 1  
Old 12-16-2009
Removing sections

I have a file like this

Code:
%( PHASES
P
%)

%( SOURCES
(10,0.0)
(13,0.0)
(16,0.0)
(19,0.0)
(22,0.0)
(25,0.0)
(28,0.0)
(31,0.0)
(34,0.0)
(37,0.0)
(40,0.0)
(43,0.0)
(46,0.0)
(49,0.0)
(52,0.0)
(55,0.0)
%)


%< SOURCE 1
%( PHASE 1
10 0 0
13 5.92346 5.92346
16 10.3106 10.3106
19 13.9672 13.9672
22 16.9838 16.9838
25 19.4407 19.4407
28 21.4705 21.4705
31 23.1547 23.1547
34 24.6813 24.6813
37 26.0695 26.0695
40 27.3611 27.3611
43 28.631 28.631
46 29.8366 29.8366
49 30.9858 30.9858
%)
%>

%< SOURCE 2
%( PHASE 1
10 5.92346 5.92346
13 0 0
16 5.92346 5.92346
19 10.3106 10.3106
22 13.9672 13.9672
25 16.9838 16.9838
28 19.4407 19.4407
31 21.4705 21.4705
34 23.1547 23.1547
37 24.6813 24.6813
40 26.0695 26.0695
43 27.3611 27.3611
46 28.631 28.631
49 29.8366 29.8366
52 30.9858 30.9858
%)
%>

Basically I need to check each section as below with list values as xyz

Code:
%< SOURCE 1
%( PHASE 1
x y z
x y z
x 0 0 
x y z
x y z
%)
%>

I get the value of x for the row x 0 0
Then I check whether the difference between this x and the other x's does not exceed a user defined value.

I have written the awk script below

Code:
function abs(val) { return val > 0 ? val : -val }

BEGIN {
    if ( ARGC != 3 ) {
        print "Usage: awk -f txcheck.awk file.tx max > error.log"
        exit 1
    }
    RS = "%<"
    FS = "\n"
    srxmax = ARGV[ARGC-1]
    delete ARGV[ARGC-1]
}

NR == 1 {
  print "Error flags when Source-Receiver distance exceeds", srxmax "Mm."
}

/SOURCE [0-9]/ {

  for ( i = 3; i <= NF; i++ )
  {
    if ( length($i) > 2 )
    {
      split( $i, a, " " ); 
      {
        if ( a[2] == 0 && a[3] == 0 )
        {
          print ""
          for ( j = 3; j <= NF; j++ ) {
            split( $j, b, " " );
            {
              if ( abs( a[1] - b[1] ) > srxmax )
              {
                valnum = ( b[1] != "" || b[1] != "%>" || b[1] != "%)" )
                if ( b[1] != "" || b[1] != "%>" || b[1] != "%)" )
                {
                  ORS = ""
                  print "ERROR: " $1 ","
                  print " sx =", a[1] ", rx = ", b[1] "\n"
                  ORS = "\n"
                }
              }
            }
          }
        }
      }
    }
  }
}

However, it is capturing the closing %) and %> and the space.

Code:
ERROR:  SOURCE 12, sx = 43, rx =  %)
ERROR:  SOURCE 12, sx = 43, rx =  %>
ERROR:  SOURCE 12, sx = 43, rx =  
ERROR:  SOURCE 12, sx = 43, rx =  

ERROR:  SOURCE 13, sx = 46, rx =  %)
ERROR:  SOURCE 13, sx = 46, rx =  %>
ERROR:  SOURCE 13, sx = 46, rx =  
ERROR:  SOURCE 13, sx = 46, rx =

# 2  
Old 12-16-2009
I run your script, and don't get the same error.

Code:
$ awk -f txcheck.awk file.tx 40Mm
Error flags when Source-Receiver distance exceeds 40MmMm.

ERROR:  SOURCE 1, sx = 10, rx =  16
ERROR:  SOURCE 1, sx = 10, rx =  19

ERROR:  SOURCE 2, sx = 13, rx =  19
ERROR:  SOURCE 2, sx = 13, rx =  22

if %) or %> has space after it, please update below code:

Code:
if ( length($i) > 2 )

maybe change 3 can fix your issue.

Code:
if ( length($i) > 3

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing sections from listener.ora

Hi, I am trying to write a script or command to add/remove a section from listener.ora file in the following example I would like: 1. to remove sid_alias2 sections 2. to add a new alias sections called sid_alias4, it can be placed after sid_alias3 sections $ cat listener.ora ... (18 Replies)
Discussion started by: ynixon
18 Replies

2. Shell Programming and Scripting

Extract certain sections of a line

I have a log that looks like below sc.mng_10_Err.20131020_000000.log:NCSSC_MNG_UP_PE_TO_BE : Failed to change dvc_trx_sts from PE to BE for srvtrx: 213323141427349 dvcsfx: 1 sc.mng_4_Err.20131020_000000.log:NCSSC_MNG_UP_PE_TO_BE : Failed to change dvc_trx_sts from PE to BE for srvtrx:... (6 Replies)
Discussion started by: senormarquez
6 Replies

3. Shell Programming and Scripting

How to remove sections of a filename?

Hello, I need some help with renaming some files by removing a certain portion of the filename. The current file name is: ABC_2013186197_20130708_203556.95336 I need to remove the 5 digits after the first "_". The new file name should be: ABC_197_20130708_203556.95336 I'm not quite... (5 Replies)
Discussion started by: bbbngowc
5 Replies

4. Shell Programming and Scripting

Omitting sections of file that contain word

I have a configuration file that contains hundreds of these chunks. Each "chunk" is the section that begins with "define service {" and ends with "}". define service { check_command check_proc!java hostgroup_name service_description ... (5 Replies)
Discussion started by: SkySmart
5 Replies

5. 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

6. 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

7. Shell Programming and Scripting

Removing sections and leaving separators intact

I have an awk script like below function abs(val) { return val > 0 ? val : -val } # 1. Main input loop, executed for each line of input BEGIN { RS = ORS = ">" } { if ( NF > 2 ) { if ( abs( $1 - $(NF-2) ) < 40 ) { print } } } The input file is something like... (2 Replies)
Discussion started by: kristinu
2 Replies

8. Shell Programming and Scripting

swaping sections of lines

Is it possible to do this with sed? Go from this: 958211 XXYYXXYYXX file1 file2 file3 958897 XXYYXXYYXX file1 file2 To this: file1 file2 file3 XXYYXXYYXX 958211 file1 file2 XXYYXXYYXX 958897 The only thing consistant is XXYYXXYYXX. The numbers and files vary in length. I have seen I... (5 Replies)
Discussion started by: crowman
5 Replies

9. 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

10. 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
Login or Register to Ask a Question