validate against a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting validate against a file
# 1  
Old 08-31-2006
validate against a file

Hello all,
I am having problem in writing a if condition for the following:
I have a file Instance.dat which has:
#Server Environment
server1 dev
server2 dev
server3 sit

Code:
#!/bin/ksh
ENV=dev
for i in $( cat Instances.dat | grep -v '#' |awk {'print $2'} )
do
  if [[ $ENV = $i ]]
    echo "You are deploying the application in $ENV Environment"
    cat Instances.dat | grep -i $ENV | awk {'print$1'} | grep -v '#' > hostnames.dat
  else
    echo "Please check the Environment"
    exit
  fi
done

Idea is to validate the Env provided in the script against the file but my script doesn't work?? Smilie
I really appreciate help on this.

Thanks
Chiru

Last edited by reborg; 08-31-2006 at 03:53 PM.. Reason: code tags
# 2  
Old 08-31-2006
Code:
if [[ $ENV = $i ]] ; then

# 3  
Old 08-31-2006
Quote:
Originally Posted by chiru_h
cat Instances.dat | grep -i $ENV | awk {'print$1'} | grep -v '#' > hostnames.dat
wow! I'm speechless!
# 4  
Old 08-31-2006
Vgresh,

I haven't tried this script but can you please let me know why u are speechless?

Thanks
# 5  
Old 08-31-2006
Code:
nawk -v env="${ENV}"  'tolower(env) ~ tolower($0) && /[^#]/ {print $1}' Instances.dat > hostnames.dat

it's called UUOC
# 6  
Old 08-31-2006
Smilie

Thankyou !!!
# 7  
Old 08-31-2006
vgersh99 !!
I didn't get what you did but I am sure it will work.
But when I just cut/pasted the command, it throws error.
I don't have nawk...Does it have to necessarily nawk ??
A lil' explanation is also appreciated..

Chiru
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Validate csv file

Hi guys, i want to validate the no.of colums in a csv file ,but if there is a comma(,) in any of the data values it should skip and count only valid (,) commas. e.g 1.abc,pqrs,1234,567,hhh result :4 2.abc,pqrs,1234,567,hhh,"in,valid",end12 result:6 here script should skip the comma inside... (10 Replies)
Discussion started by: harry123
10 Replies

2. Shell Programming and Scripting

what is the better way to validate records in a file.

hi all, We are checking for the delimited file records validation Delimited file will have data like this: Aaaa|sdfhxfgh|sdgjhxfgjh|sdgjsdg|sgdjsg| Aaaa|sdfhxfgh|sdgjhxfgjh|sdgjsdg|sgdjsg| Aaaa|sdfhxfgh|sdgjhxfgjh|sdgjsdg|sgdjsg| Aaaa|sdfhxfgh|sdgjhxfgjh|sdgjsdg|sgdjsg| So we are... (4 Replies)
Discussion started by: Seshendranath
4 Replies

3. Shell Programming and Scripting

Need script to validate file according to date

Hi All, I am very new to unix and just started to work with unix and shell scripting.I have a query anyone help would be much appreciated I am using sun solaris OS I want to validate a file according to its date and if validate successful then it would write the file name,size,date and... (3 Replies)
Discussion started by: sv0081493
3 Replies

4. Shell Programming and Scripting

validate tar file on tape

I've got a KSH/AIX question that I haven't been able to figure out yet. I've got a tape archive program that "tar's" data to a tape. After creating the archive, I'd like to somehow verify that the tape is actually good. So, what I'd like to do as a simple "sanity" check that I can read the tape... (9 Replies)
Discussion started by: dernsdorff
9 Replies

5. Shell Programming and Scripting

Validate the file

How do we validate the header file. The file number should increament by 1 (position 17 to 19) if not abend the process. first week ABC0001 20100101123 second week ABC0001 20100108124 Third week ABC0001 20100115125 (7 Replies)
Discussion started by: zooby
7 Replies

6. Shell Programming and Scripting

Validate Zip file

Hi all, How to check if the input file is zip file, If yes, validate the version of gzip utility (1 Reply)
Discussion started by: balaji23_d
1 Replies

7. Shell Programming and Scripting

Better way to Validate column data in file.

I am trying to validate the third column in a pipe delimited file. The column must be 10 char long and all digits 0-9. I am writing out two new files from the existing file, if it would be quicker, I could leave the bad rows in the file and ignore them in the next process. What I have is... (12 Replies)
Discussion started by: barry1
12 Replies

8. Shell Programming and Scripting

How to validate a CSV file?

Hi. I think some people have already asked this, but the answers/questions seem to be about validating the contents inside a CSV file. I am simply after a simple variable solution (ie 0 = false, 1 = true) that I can use in my script to say that file so-and-so is actually a CSV file, or in some... (4 Replies)
Discussion started by: ElCaito
4 Replies

9. Shell Programming and Scripting

validate csv file load

Hi All, I am using sqlldr to load my csv files into the database. The code in the sh script is as follows. sqlldr ${DBUSER}/${DBPASS}@${ORACLE_SID} \ data=myCSV.data \ bad=myCSV.bad \ control=myCSV.ctl \ ... (0 Replies)
Discussion started by: rahulrathod
0 Replies

10. Shell Programming and Scripting

validate the file name

write a shell script that check file name like pstat_24.txt (up to 5 digits) i mean to say this digit can be range from 1 to 99999 only correct file name are pstat_10000.txt pstat_12345.txt pstat_14569.txt wrong file name are pstat_1234567.txt pstat_1a2345.txt... (2 Replies)
Discussion started by: maykap100
2 Replies
Login or Register to Ask a Question