Results 1 to 2 of 2

Thread: awk getline

  1. #1
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    138

    Unanswered: awk getline

    Hi,
    how can I set FS for the lines which given in getline variable x

    #cat zahlung.neu | awk ' BEGIN { FS="@"}
    # {
    # # print $0
    # close("patient.neu")
    # while ( (getline x < "patient.neu") > 0)
    # {
    # if (substr(x,1,7) == $2)
    # {
    # # print substr(x,9)
    # name = substr(x,9)
    # print name"@"$0 > "zahlung.neu1"
    # break
    # }
    # }
    # }'

    Thanx
    Greetings from germany
    Peter F.

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    You read the file patient.neu for every record in zahlung.neu ....
    Instead, you can use the method illustrated by the following script.
    Code:
    awk '
    # Initialize FS for first file
    BEGIN {
      FS = "/"
    }
    
    # Memorize Names from first file
    FNR==NR {
      Name[$1] = $2;
      next;
    }
    
    # Set FS and OFS for second file
    FNR==1  {
      FS  = "@";
      OFS = "@";
    }
    
    # Select record where Name is present in first file
    $2 in Name {
        print Name[$2],$0;
    }
     ' patient.neu zahlung.neu > zahlung.neu1
    Jean-Pierre.

Posting Permissions

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