How to get the script corrected to get the solution


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to get the script corrected to get the solution
# 1  
Old 12-04-2008
How to get the script corrected to get the solution

Can anyone help it out,

My Requirement:

Actually i grep for the items in the atrblist (Result of it will provide the line where the item present and also the next line of where it presents)then it will be stored in $i.txt
From tat result i wil grep 2nd word after getdate() word and store it in $i_value.txt

eg: if result of $i.txt is below,
---------------------------------------------:
..'getdate(),NULL,'D','Y',NULL.....
..'Y',NULL, getdate(), NULL,'V','Y',NULL
..'getdate(),NULL,'A','Y',NULL.....
---------------------------------------------
Then result of $i_value.txt is,
---------------------------------------------
'D'
'V'
'A'
---------------------------------------------

Then i wil check whether $i is retention_cd and for values in $i_value.txt
if the value is 'A' or 'B' ... 'Z' i wil print the echo accordingly

if $i is opt_fmt_cd and for values in $i_txt
if values is PDF, XLS ... i wil print accordingly...


Above is my requirement
but the code does not work properly can any one please check my code and let me know the correct one....

NOTE:::: atrblist will be added with som new items also.

--------------------------- CODE STARTING ------------------------------------------------------------
for i in `cat $LOC/atrblist.txt`
do
echo "Registration Validation as of :" `date` > $LOC/$i.txt
nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=0 a=1 s=$i $SQLFILE >> $LOC/$i.txt
if [ $? -eq 1 ]
then
rm -f $LOC/$i.txt
exit 1
else
chmod 775 $LOC/$i.txt
cat $LOC/$i.txt | sed "s/getdate()/~&1/" | tr "~" "\n" | grep "getdate()" | cut -d"," -f3 >> $LOC/$i_value.txt
chmod 775 $LOC/$i_value.txt
if [ $i -eq retention_cd ]
then
for j in `cat \$i\_value.txt`
do
if [ $j -eq 'A' ]
then
echo "Values is" $j "So Retention code of product is : 7 Days"
else if [ $j -eq 'B' ]
then
echo "Values is" $j "So Retention code of product is : 3 Months"
else if [ $j -eq 'C' ]
then
echo "Values is" $j "So Retention code of product is : 1 Year"
else if [ $j -eq 'D' ]
then
echo "Values is" $j "So Retention code of product is : 10 Years"
else if [ $j -eq 'Z' ]
then
echo "Values is" $j "So Retention code of product is : 1 Day"
else
echo "Values is" $j "So Retention code is NOT VALID Please register correctly - Even it can be Empty but not NULL"
fi
fi
fi
fi
fi
done
fi

if [ $i -eq opt_fmt_cd ]
then
for j in `cat \$i\_value.txt`
do
if [ $j -eq 'PDF' ]
then
echo "Values is" $j "So Optional Format code of product is : PDF"
else if [ $j -eq 'XLS' ]
then
echo "Values is" $j" So Optional Format code of product is : XLS"
else if [ $j -eq 'CSV' ]
then
echo "Values is" $j" So Optional Format code of product is : CSV"
else if [ $j -eq 'TXT' ]
then
echo "Values is" $j" So Optional Format code of product is : TXT"
else
echo "Values is" $j "So Optional Format code which is NOT VALID Please register correctly"
fi
fi
fi
fi
done
fi

fi

done
--------------------------- CODE END ------------------------------------------------------------

where,
atrblist.txt is
----------------
retention_cd
opt_fmt_cd
;;
;;
-----------------

LOC = /home/path (local path)

SQLFILE:
---------------------------------------
;;
;;
values('new','retention_cd','retention_cd','C','EQUALS','N',-999, NULL,NULL,'N','N',NULL, NULL,'SYSTEM',getdate(),'0','D','0','S','N',0,'N','N','00',NULL1,NULL2,'N',NULL3,NULL4,NULL)
values('new1','opt_fmt_cd','retention_cd','C','EQUALS','N',-999, NULL,NULL,'N','N',NULL, NULL,'SYSTEM',getdate(),'0','D','0','S','N',0,'N','N','00',NULL1,NULL2,'N',NULL3,NULL4,NULL)
;;
;;
---------------------------------------
# 2  
Old 12-11-2008
That's a lot of code to debug... can you start by telling us how exactly it does not work?
# 3  
Old 12-15-2008
Quote:
Originally Posted by prsam
Code:
for i in `cat $LOC/atrblist.txt`


That is almost always the wrong way to read a file. Use a while loop and redirection:

Code:
while IFS= read -r i
do
 : do whatever
done < "$LOC/atrblist.txt"

 
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with compare 2 column content and corrected/replaced word

Input File CGGCGCCTCGCNNNCGAGCG CGGCGCGCCGAATCCGTGCG TCGCNGC GCGCCGC ACGGCNNNNN ACGGCCTCGCG CGGCNGCCCGCCC CGGCGCGCCGTCC Desired Output File CGGCGCCTCGCNNNCGAGCG CGGCGCGCCGAATCCGTGCG CGGCGCCTCGCATCCGAGCG TCGCNGC GCGCCGC TCGCCGC ACGGCNNNNN ACGGCCTCGCG ACGGCTCGCG... (6 Replies)
Discussion started by: perl_beginner
6 Replies

2. Shell Programming and Scripting

Script solution as singleline ?

Hello My script has following line and output find path -type d | awk -F "/" 'NF == 4{print $3}' path/custype=Type1/logdate=20160414 path/custype=Type11122/logdate=20160414 But I need following output that I need custtype information between "" like... (4 Replies)
Discussion started by: msuluhan
4 Replies

3. Shell Programming and Scripting

Sed command needs to be corrected.

Hi All, I am writing a simple script for find and replace strings in a bunch of files.Everything looks good except for the sed command , since it has a "/" in the search command and "$" in the replace string. Please find the script below. Can someone please help me in getting to the right sed... (1 Reply)
Discussion started by: nua7
1 Replies

4. Shell Programming and Scripting

Perl script solution

Hi I need to do this thing in awk (or perl?). I try to find out how can I identify 1st and 2nd result from the OR expression in gensub: block='title Sata Mandriva kernel /boot/vmlinuz initrd /boot/initrd.img' echo "$block" | awk '{ x=gensub(/(kernel|initrd) /,"\\1XXX","g"); print x }' ... (12 Replies)
Discussion started by: webhope
12 Replies
Login or Register to Ask a Question