Validate file prefixed with characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Validate file prefixed with characters
# 1  
Old 08-05-2010
Java Validate file prefixed with characters

i have to check a file prefixed with ABC_, XYZ_ etc
For example : ABC_add
kindly give some ideas for validating the file prefixed with characters using SHELL script

i tried as follows but it is failing
Code:
f1='ABC_'
if [ ! -f $f1$file ]
then
echo "f1 passed";
fi


Last edited by pludi; 08-05-2010 at 04:06 AM.. Reason: code tags, please...
# 2  
Old 08-05-2010
Hi.

Your code looks OK (for a single file) so long as $file is set.

What is failing?
# 3  
Old 08-05-2010
for a single file its OK
i am checking multiple files.... i.e n number of times if is executed
Code:
f1='ABC_'
f2='XYZ_'
f3='DHF_'

if [ ! -f $f1$file ]
then
echo "f1 passed";
if [ ! -f $f1$file ]
then
echo "f1 passed";
if [ ! -f $f1$file ]
then
echo "f1 passed";
fi

always "f1 passed" message is displayed

Last edited by Scott; 08-05-2010 at 04:47 AM.. Reason: Code tags, please...
# 4  
Old 08-05-2010
Your script doesn't really work:

Code:
f1='ABC_'
f2='XYZ_'
f3='DHF_'

if [ ! -f $f1$file ]
then
echo "f1 passed";
fi

if [ ! -f $f2$file ]
then
echo "f2 passed";
fi

if [ ! -f $f3$file ]
then
echo "f3 passed";
fi

What is the value of the file variable?
# 5  
Old 08-05-2010
Java

file will be holding static value....
for example ABC_file1
# 6  
Old 08-05-2010
Hi.

I cannot see a problem now...

A quick test:
Code:
$ cat fileTest
f1='ABC_'
f2='XYZ_'
f3='DHF_'

file=file1
touch $f1$file

if [ ! -f $f1$file ]
then
echo "f1 passed";
fi

if [ ! -f $f2$file ]
then
echo "f2 passed";
fi

if [ ! -f $f3$file ]
then
echo "f3 passed";
fi


$ ./fileTest
f2 passed
f3 passed

Perhaps the files are located somewhere else? Not in the directory you run the script from.
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

Removing non-unique prefixed lines from a list

Not quite sure how to explain what I need to do (or how to title the post!) so will try and show it! Basically I have a list of 'modules' which takes the form seen below, where there can be a module name, module type and module version (a module may not have each of those and could in theory... (2 Replies)
Discussion started by: chrissycc
2 Replies

3. 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

4. UNIX for Dummies Questions & Answers

searching words & print prefixed string after it

I have a text which I divided them into sentences and now printed them in a rows. I want to get the list of most of words ( the, and, a) and print 5 words after them (so 6 with the word itself). I have created an acceptfile with those rows and using grep but I have rows that have these words more... (2 Replies)
Discussion started by: A-V
2 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

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 #!/bin/ksh ENV=dev for i in $( cat Instances.dat | grep -v '#' |awk {'print $2'} ) do if ]... (7 Replies)
Discussion started by: chiru_h
7 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 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

10. Shell Programming and Scripting

validate input from user for file name

Hello, This may have been addressed already somewhere, however I am looking for the easiest/shortest way to validate a response from a user for a file name. The file name should not have any of the following characters ~`!@#$%^&*()_-+={|\:;"'<,>.?/ Further the response should not have any... (2 Replies)
Discussion started by: jerardfjay
2 Replies
Login or Register to Ask a Question