HELP is needed! 
Author Message
 HELP is needed!

Hi,
        I have this text file (infile) that contains the shown example below
but this "infile" contains lots of the shown example.

infile:

The house number is 100-1 (Hello there):
        QG 214 house in the street 82-3 near 8 marked
        QG 214 house in the street 109-3 near 30

The house number is 336-8 (Hi there):
        QG 304 house in the street 19-4 near 7
        QG 204 house in the street 8-3 near 10 marked
        QG 304 house in the street 7-5 near 9 marked
        QG 380 house in the street 86-6 near 5
        QG 380 house in the street 200-1 near 25 marked
        QG 204 house in the street 1-4 near 4

.... and so on. (not included in the "infile")

        How can I use awk so that I can have an output that would look like the
one shown below.  Please take note that it only process the numbers
(with -) in first line of every paragraph and the succeeding lines in
the paragraph with numbers (also with -) and it ends with "marked".  

output:

100     1       82      3
82      3       100     1
336     8       8       3
8       3       336     8
336     8       7       5
7       5       336     8
336     8       200     1
200     1       336     8

Note:  (Output is tab delimited)

        I tried using "grep" and "awk" but somehow at a lost as to how to
arrived with the desired output.   My knowledge with "awk" is still at
"beginners level".
        Any suggestions is greatly appreciated.
        You can email me to my email address or maybe respond to this
"newsgroup".
        Thank you very much.

Albert



Mon, 30 Apr 2001 03:00:00 GMT  
 HELP is needed!
The following program was tested with your data and produced the desired
results.

{
 split($5,hn,"-")
 rtcode=getline
 if (rtcode < 1) exit
 while (NF > 0) {
  if (/marked$/) {
   split($7,nh,"-")
   printf "%s\t%s\t%s\t%s\n", hn[1], hn[2], nh[1], nh[2]
   printf "%s\t%s\t%s\t%s\n", nh[1], nh[2], hn[1], hn[2]
  }
  rtcode=getline
  if (rtcode < 1) exit
 }

Quote:
}

In this program, I made some assumptions:
1. the "-" which identifies the numbers to be processed always occurs on
field 5 of the first line of each paragraph
2. the lines which you say are marked have the text "marked" as the end of
the line
3. these marked lines take the numbers from field 7
4. there is no checking done to see if the values on either side of the "-"
are valid (in either point 1. or point 3. above)

Anyway, with the limited sample data you gave, this program should do the
trick for you.

Cesar

--
Please remove the UPPERCASE characters from my e-mail address for the real
thing

Quote:
>Hi,
> I have this text file (infile) that contains the shown example below
>but this "infile" contains lots of the shown example.

>infile:

>The house number is 100-1 (Hello there):
> QG 214 house in the street 82-3 near 8 marked
> QG 214 house in the street 109-3 near 30

>The house number is 336-8 (Hi there):
> QG 304 house in the street 19-4 near 7
> QG 204 house in the street 8-3 near 10 marked
> QG 304 house in the street 7-5 near 9 marked
> QG 380 house in the street 86-6 near 5
> QG 380 house in the street 200-1 near 25 marked
> QG 204 house in the street 1-4 near 4

>.... and so on. (not included in the "infile")

> How can I use awk so that I can have an output that would look like the
>one shown below.  Please take note that it only process the numbers
>(with -) in first line of every paragraph and the succeeding lines in
>the paragraph with numbers (also with -) and it ends with "marked".

>output:

>100 1 82 3
>82 3 100 1
>336 8 8 3
>8 3 336 8
>336 8 7 5
>7 5 336 8
>336 8 200 1
>200 1 336 8

>Note:  (Output is tab delimited)

> I tried using "grep" and "awk" but somehow at a lost as to how to
>arrived with the desired output.   My knowledge with "awk" is still at
>"beginners level".
> Any suggestions is greatly appreciated.
> You can email me to my email address or maybe respond to this
>"newsgroup".
> Thank you very much.

>Albert



Mon, 30 Apr 2001 03:00:00 GMT  
 HELP is needed!

Quote:
> infile:

> The house number is 100-1 (Hello there):
>         QG 214 house in the street 82-3 near 8 marked
>         QG 214 house in the street 109-3 near 30

> output:

> 100     1       82      3
> 82      3       100     1

> Note:  (Output is tab delimited)

>         I tried using "grep" and "awk" but somehow at a lost as to how

The following code should do the trick. It assumes that: the first line
always begins an column 1 and no other lines do; that the word "marked"
is unique to the lines you want; and that the relative field numbers are
fixed (5 in the header, 7 in the 'marked').

substr($0,1,1)!=" "{split($5,x,"-")}
$NF="marked"       {split($7,y,"-")
                    printf("%d\t%d\t%d\t%d\n",x[1],x[2],y[1],y[2])
                    printf("%d\t%d\t%d\t%d\n",y[1],y[2],x[1],x[2])
                   }
--
Bob Stearns
University of Georgia

(706)542-5110



Mon, 30 Apr 2001 03:00:00 GMT  
 HELP is needed!


[input]
% The house number is 100-1 (Hello there):
%       QG 214 house in the street 82-3 near 8 marked
%       QG 214 house in the street 109-3 near 30

[...]

% output:
%
% 100   1       82      3
% 82    3       100     1

[...]

It seems like all the follow-on lines start with QG, so I'd suggest
using that to detect the first line of the paragraph. You can then
save the house number and look for the lines with `marked' on them.
This assumes the text is fixed -- you'll have to be more clever about
figuring out the house numbers if it isn't.

  !NF { next }
  ! /QG/ { split( $5, thishouse, "-"); next }

  /marked/ { split($7, thathouse, "-")
    print thishouse[1] "\t" thishouse[2] "\t" thathouse[1] "\t" thathouse[2]
    print thathouse[1] "\t" thathouse[2] "\t" thishouse[1] "\t" thishouse[2]
  }
--

Patrick TJ McPhee
East York  Canada



Wed, 02 May 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. i am a lamer and i need your help :-)

2. I NEED HELP WITH AN ERROR I GET IN THIS ASSIGNMENT I AM CLOSE TO FINISHING

3. i am new need help

4. I am a student and need some help...

5. i am in desperate need of help

6. ***HELP***HELP***NEED INFORMATION***HELP***HELP

7. I am not deaf, but am I mute?

8. i am new and need info

9. Help - What am I doing wrong

10. HELP, I am Clarion Newbie

11. Help, I am a Clarion Newbie

12. Help I am having an Internal error:tpsbt.cpp line 1477

 

 
Powered by phpBB® Forum Software