Help w/awk, korn shell & writing to a file

Help w/awk, korn shell & writing to a file

Post by Ms. Terry L » Thu, 28 Jul 1994 01:58:28

First, this post is cross posted to comp.unix.questions, .shell &
.programmer.....I desparately need help.

I am using korn shell on a Pyramid box running OSx Unix.

I am trying to write a shell script that will echo out a line of data (that is
read from a file) based upon a user's login id.

This is basically what I have:

#Based on the LOGNAME/USERID, a variable, namely flag, is set to 0,1 or 2 for
#how many to look thru file userid.dat looking for the correct string to
#output.  #For instance, userid.dat may have:


#end of file userid.dat

From this file, say userids of tmlee5* would use the 2nd line (userid's  
tmlee50-59), all other userids of tmlee* would use the 1st line.'s part of the shell script:

awk 'BEGIN {FS = "|'; OFS=", "; ORS="" }

# Load array with the user privileges...also based on userid


0 ~ /'"$search"'/{
     if ($flag==2){       #  Loop 2 times to get to correct line in userid.dat
     if ($flag==1){

# This part is the problem.
 print $1 OFS $2 OFS $3 OFS $4 OFS $5 OFS $6 OFS id_array[$7] OFS ORS >> mycrc

Quote:}' userid.dat

....other code to access file 'crc'.

This doesn't work....I always get the 1st line.

If I try:

if ($flag==0){
  print ..... >> mycrc


the file is never created but if I use a test "echo" before printing I'll get
both the 1st line & part of the 2nd line.   I've tried moving 'mycrc="crc" '
before the awk & using $mycrc as well as plain mycrc....both don't work.  I've
tried using printf....that doesn't work or I can't get it to work.

Any clues?  Am I just making this harder that it has to be?  Please
help.....this is driving me crazy.