Data Validation


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Data Validation
# 1  
Old 12-15-2005
Data Validation

Hello,

I am trying to use data validation with a program. I have everything else working fine. I just can't figure out what I am doing wrong with the data validation in one of my files. Here is the code:
Code:
# data validation loop
     while :
     do

          # get input from keyboard
          echo "Please enter your search keyword(s):"
          read keywords

          # if statement
          if [ "$keywords" = "" ]

          # then statement
          then

               # display error message
               echo "Error, you have not entered keywords!"
               echo "Please try again."
               # continue data validation loop
               continue

          else

               # display good message
               echo "Great, keep going!"
               # break out of data validation loop
               break

          fi
          # end of if statement

     done
     # end of data validation loop

     # here document redirects input of a command from here
     cat<<alldone2

          ${bell}

alldone2
# end of here document

     # display keyword search matches
     grep -in "$keywords" $phonebook|sed -n -e 's/^/\
                        /' -e 's/:/\
                        /gp'


      # here document redirects input of a command from here
      cat<<alldone3

           ${bell}

 alldone3
 # end of here document

      # data validation loop
      while :
      do

           # get input from keyboard
           echo "Please enter the record number of the particular record to remove:”
           read number

           total = `cat $phonebook|wc -l`

           # if statement
           if [ "$number" != "" ]
           then if [ $number -ge 1 -a $number -le $total  ]

                then
                     #display message
                     echo "Great job, keep going!"
                     #break out of data validation loop
                     break

                else
                     #display error message
                     echo "The number is not in the range."
                     echo "Please try again."
                     # continue data validation loop
                     continue

                fi
                #end of if statement

           else

                #display error message
                echo "You did not enter a number!"
                #continue data validation loop
                continue

           fi
           # end of if statement

      done
      # end of validation loop

      # command substitution assigns the output of sed to record
      record=`sed -n ${number}p $phonebook`

      # remove the record using the number selected by the user
      grep -iv "$record" "$phonebook" > $tmp

      # rename tmp to phonebook
      mv $tmp $phonebook

      # change permissions for phonebook datafile
      chmod 755 $phonebook

      # get input from keyboard
      echo "Do you want to remove more records? \c"
      read answer

When I use verbose and execution trace, here is what I get:
Code:
+ :
+ echo Please enter your search keyword(s):
Please enter your search keyword(s):
+ read keywords
bob
+ [ bob =  ]
+ echo Great, keep going!
Great, keep going!
+ break
+ cat






+ sed -n -e s/^/\
                        / -e s/:/\
                        /gp
+ grep -in bob /fun/phonebook

                        3
                        bob again
                        778 bob lane
                        bob city
                        bob state
                        11111
                        1111111111
+ cat






+ :
+ echo Please enter the record number of the particular record to remove.
Please enter the record number of the particular record to remove.
+ read number
3
+ wc -l
+ cat /fun/phonebook
+ total = 3
remove: total: execute permission denied
+ [ 3 !=  ]
+ [ 3 -ge 1 -a 3 -le ]
remove: test: argument expected

Thank you,
Eric
# 2  
Old 12-15-2005
is this is a typo?

Code:
 total = `cat $phonebook|wc -l`

if the above statement is used as such,
line count will not be assigned to total,

use

Code:
total=`cat $phonebook|wc -l`

# 3  
Old 12-15-2005
Thanks

I feel like a big dummy.

Thanks for pointing that out. That took care of my problem. I will continue practicing.

Thanks,
Eric
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Source data validation

I am using below logic to validate whether i am expecting the correct data from source,if not logic should give which column has error.i am running below logic in linux awk -F, ' NR==1{next} {f=" "} $1!~/^{0,5}$|^$/{f=f?f" emp_id-error":"emp_id-error"} $4!~/^{0,6}$|^$/{f=f?f"... (4 Replies)
Discussion started by: katakamvivek
4 Replies

2. Shell Programming and Scripting

Help With UNIX Shell Scripting For Data Validation

Hi All, I am completely new to Unix Shell Scripting. I m validating(Basic File Validation) an .HHT file in TIBCO. After that i need to do Data Validation through UNIX Shell scripting. Rules in DataValidation: 1.) Need to Check Every field wheather it is a Char or Number?(Fields are... (1 Reply)
Discussion started by: Chaitanya K
1 Replies

3. Shell Programming and Scripting

Data validation engine

Generic Data validator Data file: Name,Sal,Dept ABC,1234,D1 AYX,12356,D2 DHF,345,ED3 123,4565,FGJG Config File: Delimiter-"," Rule1-Name- Rule2-Sal- Rule3-Dept-* Can be used to match any regex including date different format and numbers. (3 Replies)
Discussion started by: dikesm
3 Replies

4. Shell Programming and Scripting

basic data validation

hpux. older version. don't have alot of the newer features in some utilities. How do I verify that a variable starts with the letter A. I would like to make it case insensitive. Also, if I have a variable that has letters and numbers. I want to change all the lower case letters to upper case.... (2 Replies)
Discussion started by: guessingo
2 Replies

5. Shell Programming and Scripting

File and Data Validation.

Hello, I am working on an interface between a legacy system and an ERP system.The format of the data extracted into the staging folder from the legacy system is a follows. One control file named ExtractDataControl.txt Multiple entity files eg R1001.txt, R1002.txt, R1020.txt The control... (5 Replies)
Discussion started by: Savio_Saldanha
5 Replies

6. Shell Programming and Scripting

Data Validation

I have a comma delimited file that I need to validate the data in one two columns in. Sample File: 1234,1234,1234,DESCRIPTION,1,1,2 1234,1234,1234,DESCRIPTION,1,1,2 1234,1234,1234,DESCRIPTION,1,1,2 1234,1234,1234,DESCRIPTION,1,1,2 I need to make sure that the second column's entries are... (3 Replies)
Discussion started by: hmnetonline
3 Replies

7. Shell Programming and Scripting

shell script data & time validation

How to validate a date and optionly a time in shell scripting when i get the date and time as pararmeters that sent out with the call of the file? (in my case sh union.sh `first parameter ,second parameter...` (4 Replies)
Discussion started by: tal
4 Replies

8. Shell Programming and Scripting

validation of data using filter (awk or other that works...) in csv files

Hello People I have the following file.csv: date,string,float,number,boolean 20080303,abc,1.5,123,Y 20080304,abc,1.2,345,N 20080229,nvh,1.4,098,Y 20080319,ugy,1.9,586,N 20080315,gyh,2.4,345,Y 20080316,erf,3.1,932,N I need to filter the date field where I have a data bigger than I... (1 Reply)
Discussion started by: Rafael.Buria
1 Replies

9. UNIX for Advanced & Expert Users

awk data validation

Hi , This is a general doubt.... Is there any way to do data validation inside an awk script.. Let me make it more clear.... I have a string variable inside awk script .. Is there any way to check whether it is number or string etc... Thanks in advance. Shihab (1 Reply)
Discussion started by: shihabvk
1 Replies
Login or Register to Ask a Question