Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2004
    Posts
    46

    Unanswered: plz...can anyone modify this script

    HTML Code:
    file=$1
    var1=`nawk -F~ '{ for( i = 1; i<= NF; ++i )
    if ( $i != "" ) { print "'"'"'"$i"'"'"'""," }
    else {print"NULL,"}}' $file`
    
    var2=`echo $var1 | sed -e 's/, /,/g;s/,$//g'| sed 
    's/'\'SYSDATE\''/SYSDATE/g'`
    
    #echo $var2
    
    var3= `nawk -F, '{ for( i = 1; i<= NF; i++ )
    if ( i == 5 ) { echo $i | sed 's/'\'"$i"\''/"$i"/g' }
    elseif ( i == 8 ) { echo $i | sed 's/'\'"$i"\''/"$i"/g' }
    elseif ( i == 23 ) { echo $i | sed 's/'\'"$i"\''/"$i"/g' }
    elseif ( i == 38 ) { echo $i | sed 's/'\'"$i"\''/"$i"/g' }
    elseif ( i == 40 ) { echo $i | sed 's/'\'"$i"\''/"$i"/g' }
    elseif ( i == 42 ) { echo $i | sed 's/'\'"$i"\''/"$i"/g' }
    else { print "$i" } }'$var2`
    
    echo $var3
    my input
    :~~~~6852~TA~APM_0003~35~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~TEST
    APM_0003->GFSTM_EMAIL_PROCESS_EXCEPT_PR~~~~~~~~APMDV_SRC~TO _DATE(2-06-2004 08:16:18,DD-MM-YYYY HH24:MIS)~APMDV_SRC~TO_DATE(2-06-2004
    08:16:18,DD-MM-YYYY HH24:MIS)~TO_DATE(2-06-2004 08:16:18,DD-MM-YYYY
    HH24:MIS)~Oracle Error~

    desired
    output
    :NULL,NULL,NULL,NULL,'6852','TA','APM_0003','35',N ULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,N ULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,N ULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,N ULL,NULL,NULL,NULL,'TEST
    APM_0003->GFSTM_EMAIL_PROCESS_EXCEPT_PR',NULL,NULL,NULL,NUL L,NULL,NULL,NULL,'APMDV_SRC','TO_DATE(2-06-2004
    08:16:18,DD-MM-YYYY HH24:MIS)','APMDV_SRC','TO_DATE(2-06-2004
    08:16:18,DD-MM-YYYY HH24:MIS)','TO_DATE(2-06-2004 08:16:18,DD-MM-YYYY
    HH24:MIS)','Oracle Error',NULL




    TO_DATE(2-06-2004 08:16:18,DD-MM-YYYY HH24:MIS) should not be in
    quotes like sysdate.

    if sysdate and to_date are coming with quotes then i should remove quotes and if they are not coming with quotes then leave as it is... i am trying out above code its not working... is there any other effiecient way to do the above requirment.

    Thanks
    Markjason.

  2. #2
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    how 'bout this awk snippet:

    Code:
    BEGIN {
      FS="~"
      OFS=","
    }
    
    function doField(str)
    {
      sub("^[ ]*", "", str);
      sub("[ ]*$", "", str);
    
      str = (match(str, /[A-Za-z0-9]/)) ? "'" str "'" : str "NULL";
    
      return str
    }
    
    {
      for(i=1; i <= NF; i++)
        printf("%s%s", doField($i), (i==NF) ? "\n" : OFS);
    }

  3. #3
    Join Date
    Jun 2004
    Posts
    46
    thanks,

    Seems like i need to get more handle on awk , anyway thanks for your code, it works efficiently


    thanks,
    Mark

  4. #4
    Join Date
    Jun 2004
    Posts
    46
    can i get any good books on shell scripting or awk ,i am just a beginner who know few commands


    thanks
    Mark.

  5. #5
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325

Posting Permissions

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