reference to other file 
Author Message
 reference to other file

Hi

I have a file "online" like that:

l123 is on ...
k234 is ....
d810 ....
z422 ....
....

(.... means there are some more words)
and its content change constantly
eg. l123 could be replace by other thing such as h231 etc.

Also, the first field (eg z422) is in another file call "people":

z422 paul
l123 peter
d810 mary
....

My problem is to find out if a person is online, by giving the id (l123)
as a parameter to an awk program.
If so, print out the following:

peter l123 is on ...

I would be greatly appreciated if someone can help me out.



Mon, 28 Feb 2000 03:00:00 GMT  
 reference to other file


Quote:
>I have a file "online" like that:
>l123 is on ...
>k234 is ....
>d810 ....
>z422 ....
>....
>Also, the first field (eg z422) is in another file call "people":
>z422 paul
>l123 peter
>d810 mary
>....
>My problem is to find out if a person is online, by giving the id (l123)
>as a parameter to an awk program.
>If so, print out the following:
>peter l123 is on ...

What about:

#!/bin/ksh
if [[ $# -eq 0 ]]
then
        print "Usage: $0 SomeOneName"
        exit 1
fi
awk -F"[ \t]+" '
BEGIN {
        Found=0;
        SomeOneName="'$1'";
        #
        # read /tmp/people to find what Id someone is associated with
        #
        SomeOneId="Unknown";
        while ( (getline < "/tmp/people") == 1 ) \
        {
                if ( SomeOneName == $1 ) \
                {
                        SomeOneId=$2
                }
        }
        #
        # Exit if unknown Name
        #
        if ( SomeOneId == "Unknown" ) \
        {
                print "Unknown "SomeOneName
                exit 1
        }

Quote:
}

{
        if ( $1 == SomeOneId ) \
        {
                print SomeOneName":"$0;
                Found=1;
                #
                #
                # In case SomeOnename can be online more than once, remove the
                # following exit line
                exit 0;
        }
Quote:
}

END {
        if ( Found == 0 ) \
        {
                print SomeOnename" is not online";
        }
Quote:
}

' /tmp/online

Quote:
>>>>>>>>>>>>> Note that I did not test it >>>>>>>>>>>>>>>>>>>>>>>

Hope this helps,
Patrice.

----------------------------------------------------------------------

|  #include <disclaimer.h>  | V-mail : (+33) [0]4 92 29 39 49 + 3902 |
----------------------------------------------------------------------



Tue, 29 Feb 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How create an image file whith CLARION (.BMP or others)

2. Relating a record to others in same file

3. Index File Help (Attn: Thane and others)

4. Detecting when a file is in use by others

5. Global variables in FILE declaration, FILE references; C4b

6. Cross reference with third INPUT-FILE while updating MASTER-FILE

7. Binary filing and circular references

8. text file cross-reference utility

9. proper assignment on referenced &file

10. Trouble with reference variable to open a file

11. Reference resource file in a DLL

12. Reference resources files in code

 

 
Powered by phpBB® Forum Software