Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2009
    Posts
    3

    Unanswered: URGENT : Compare field in two files for mixed O/P

    Hi Experts,

    I have a problem. Can you Help me?

    I need a UNIX shell script for the below logic using AWK. The logic must lay on by vaildating the first field.I am using -KSH.

    I am in real hurry. : Your help will be highly appreciated.

    Table 1:

    Cricket 16 28
    Tennis 26 15
    Wrestling 12 34

    Table 2:
    Cricket 25 26
    Rugby 16 13
    Wrestling 11 22

    I need output as in table3.


    Table 3:

    Cricket 16 28 25 26
    Rugby NA NA 16 13
    Tennis 26 15 NA NA
    Wrestling 12 34 11 22

    If any questions plz ask me. Thankyou for your consideration.

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Looks easy enough - can you explain why it's urgent? why it needs to be in awk? or is it just late homework you'd rather we did for you?

  3. #3
    Join Date
    Jun 2009
    Posts
    3
    I have to findout the logic and I am learning "AWK" too.

    Teach/suggest me if you can. Thanks for your consideration.

  4. #4
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    This site's not bad.

    Read in data from files, assign values to arrays, print values out in required format, stop.

  5. #5
    Join Date
    Jun 2009
    Posts
    3

    Angry

    Hi...

    I already know how to print this format. But my concern is that the program should validate the first field (As I specified earlier), then it must the print the O/P in required format.

    Could you plz give me ur valuable inputs?

  6. #6
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Quote Originally Posted by hunter85
    I already know how to print this format. But my concern is that the program should validate the first field (As I specified earlier), then it must the print the O/P in required format.
    Validate it in what fashion, that it's spelt correctly? that it begins with a capital letter? that it's followed by 2 numbers?

    Quote Originally Posted by hunter85
    Could you plz give me ur valuable inputs?
    I'd suggest you go along to classes, do any background reading and then do your own homework. If you can't be bothered to put any effort into it then why on earth should we?

  7. #7
    Join Date
    Jun 2009
    Posts
    2

    Thumbs down comparing two files...

    @HUNTER

    awk ' FILENAME==ARGV[1] { a[$1]=$2" "$3 }
    FILENAME==ARGV[2] { if(a[$1]=="") {a[$1]="NA NA "$2" "$3 } else { a[$1]=a[$1]" "$2" "$3 } }
    END { for(i in a) print i" "a[i]}' f1 f2 | sort |
    awk '{ if(NF<4) { print $0" NA NA"} else { print $0 }}'


    it will solve ur problem....

  8. #8
    Join Date
    Jun 2009
    Posts
    2

    Thumbs down

    Quote Originally Posted by hunter85
    Hi Experts,

    I have a problem. Can you Help me?

    I need a UNIX shell script for the below logic using AWK. The logic must lay on by vaildating the first field.I am using -KSH.

    I am in real hurry. : Your help will be highly appreciated.

    Table 1:

    Cricket 16 28
    Tennis 26 15
    Wrestling 12 34

    Table 2:
    Cricket 25 26
    Rugby 16 13
    Wrestling 11 22

    I need output as in table3.


    Table 3:

    Cricket 16 28 25 26
    Rugby NA NA 16 13
    Tennis 26 15 NA NA
    Wrestling 12 34 11 22

    If any questions plz ask me. Thankyou for your consideration.


    awk ' FILENAME==ARGV[1] { a[$1]=$2" "$3 }
    FILENAME==ARGV[2] { if(a[$1]=="") {a[$1]="NA NA "$2" "$3 } else { a[$1]=a[$1]" "$2" "$3 } }
    END { for(i in a) print i" "a[i]}' Table11 Table2 | sort |
    awk '{ if(NF<4) { print $0" NA NA"} else { print $0 }}' > Table3


    now Table3 will contain .... wt u want.......

    Cricket 16 28 25 26
    Rugby NA NA 16 13
    Tennis 26 15 NA NA
    Wrestling 12 34 11 22

    Enjoyyyyyyyyyyyyyyyyyyy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •