Problem with dots within a file (Please HELP ME 
Author Message
 Problem with dots within a file (Please HELP ME

Quote:

> Actually, I do like this answer better than mine (besides that
> mine is slightly wrong), but I'd still probably do it in sed:

Hah!  And I rather liked your answer and agree:  it'll certainly
run faster if done in sed.

Nicki



Thu, 04 Apr 2002 03:00:00 GMT  
 Problem with dots within a file (Please HELP ME
Interesting problem.  I learned a few things on this one...

Anyway, I actually took the sledge hammer, much less elegent, approach:

#!/bin/ksh
read d?"Enter Number: "

gawk -v d=$d '
{
    ##  translate pesky periods
    gsub("\\.","-",d)

    # gotta get the first input line
    rec=$0
    while ( 1 )
    {
        # xlate those pesky dots
        gsub("\\.","-",rec)

        split(rec,a)

        printf("pattern = [%s]   data = [%s]\n",d,a[2])

        if ( a[2] == d )
        {
            lt=3
            while (lt>0 )
            {
                getline
                printf("\tFound it:\t%s\n",$0)
                lt--
            }
        }
        if ( ! (getline rec)  )
        {
            break
        }
    }

Quote:
}' lease.dat

[ /home1/users/dmeans/work ]

15$ lease
Enter Number: 33.44.15.3
pattern = [33-44-15-3]   data = [33-44-15-3]
        Found it:             starts 6 1999/10/16 14:14:53;
        Found it:             ends 2 1999/10/19 14:14:53;
        Found it:             hardware ethernet 00:00:00:00:00:00;
pattern = [33-44-15-3]   data = [01:00:00:00:00:00:00;]
pattern = [33-44-15-3]   data = ["dgdgff";]
pattern = [33-44-15-3]   data = []
pattern = [33-44-15-3]   data = [333-444-150-38]
pattern = [33-44-15-3]   data = [6]
pattern = [33-44-15-3]   data = [2]
pattern = [33-44-15-3]   data = [ethernet]
pattern = [33-44-15-3]   data = [01:00:00:00:00:00:00;]
pattern = [33-44-15-3]   data = ["dgdgff";]
pattern = [33-44-15-3]   data = []
pattern = [33-44-15-3]   data = [333-444-140-216]
pattern = [33-44-15-3]   data = [6]
pattern = [33-44-15-3]   data = [2]
pattern = [33-44-15-3]   data = [ethernet]
pattern = [33-44-15-3]   data = [00:00:00:00:00:00;]
pattern = [33-44-15-3]   data = ["fgfg";]
pattern = [33-44-15-3]   data = []
pattern = [33-44-15-3]   data = [333-444-14-247]
pattern = [33-44-15-3]   data = [6]
pattern = [33-44-15-3]   data = [2]
pattern = [33-44-15-3]   data = [ethernet]
pattern = [33-44-15-3]   data = [01:00:00:00:00:00:00;]
pattern = [33-44-15-3]   data = ["ddfg";]
pattern = [33-44-15-3]   data = []
Quote:

> I am treating this file:

> ....

> lease 333.444.150.38 {
>       starts 6 1999/10/16 14:14:53;
>       ends 2 1999/10/19 14:14:53;
>       hardware ethernet 00:00:00:00:00:00;
>       uid 01:00:00:00:00:00:00;
>       client-hostname "dgdgff";
>       }
> lease 333.444.140.216 {
>       starts 6 1999/10/16 14:14:24;
>       ends 2 1999/10/19 14:14:24;
>       hardware ethernet 00:00:00:00:00:00;
>       uid 00:00:00:00:00:00;
>       client-hostname "fgfg";
>       }
> lease 333.444.14.247 {
>       starts 6 1999/10/16 14:08:25;
>       ends 2 1999/10/19 14:08:25;
>       hardware ethernet 00:00:00:00:00:00;
>       uid 01:00:00:00:00:00:00;
>       client-hostname "ddfg";
>       }
>           ....

>  And this is a part of my ksh script:

> echo "Enter a number"
> read  d
> #d=`echo $d | sed 's/\./\\./g'`  "I was told to try this, but it
> #doesn't work either.
> cat file1|awk "/$d/{lt=3} lt>0{print;
> --lt}" >file2

> I'm trying to get every line matching $d and the following 2 lines
> which belong with it.
> It works alright if the input is "333.444.140" or "333.444.140." .
> But if the input is, say "333.444.14" or "333.444.14." I get
> wrong results because it greps also
> 333.444.140
> 333.444.141
> 333.444.142
> and so on.
> I think the problem lies in this dot "." but I don't know how
> to solve it.Please help me find a simple solution in ksh with awk
> or gawk.
> Would really appreciate any advice.

>                    Ian Moltke


> --
> Posted via Talkway - http://www.talkway.com
> Exchange ideas on practically anything (tm).



Thu, 04 Apr 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Problem with dots within a file (Please HELP ME

2. Problems seperating text within a string - Help Please!

3. dot-dot-dot

4. VSE 3.1 Repository Problem: Please help (please please?)

5. File Conversion Problem - Please Help

6. Please help for "File open problem"

7. Please help, DBT file problem

8. please, please, please, please, help

9. will someone please, please, please, please HELP me?!!

10. pb with proble-file and dot file

11. quick help needed: reading from a file within awk

12. Workaround for the problem with groups within a file definition

 

 
Powered by phpBB® Forum Software