If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > plz...can anyone modify this script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-29-04, 12:13
markjason markjason is offline
Registered User
 
Join Date: Jun 2004
Posts: 46
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.
Reply With Quote
  #2 (permalink)  
Old 08-30-04, 10:54
vgersh99 vgersh99 is offline
Registered User
 
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);
}
Reply With Quote
  #3 (permalink)  
Old 08-30-04, 12:48
markjason markjason is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 08-30-04, 14:46
markjason markjason is offline
Registered User
 
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.
Reply With Quote
  #5 (permalink)  
Old 08-30-04, 15:12
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On