Reg : binary files

HI Friends,

My actual requirement is to find out the binary files except txt/gif from parent and subdirectories. so,i have to write unix shell script.

Any one please suggest me on this how to write script for this or any other alternate way is there to find out.

Thanks & Regards,
Srujana

You can use "find" to recurse through the directories.

How are you going to tell the difference between binary files and text files?

really i am new to unix...
i am not sure how to differentiate, if you know please suggest me.

What is your actual requirement? What makes binary files special? Do you mean programs, ELF files or anything that has bit 7 set in any character?

my actual requirement is,

I want to find out the text files(ex:.html,.txt) and binary files(ex:.jpg) from each directory. From binary files at last i need only .gif files, reamining all i have to ignore.

after getting result, I have to archive those files and needs to checkin into CVS.

I hope my requirement is clear now.

find dir -type f | while read N
do
      case "$N" in
      *.txt | *.html )
              do whatever with text file "$N"
              ;;
      *.gif | *.jpg | *.jpeg )
              do whatever with binary file "$N"
             ;;
      * )
             ;;
      esac 
done

Hi,

I saved above script with .sh and ran after that getting error "scrip.sh: syntax error at line 5: `do' unexpected"
in above script "N" means what, i guess its referring to dir path right? if its referring to dir path then where to mention path.

suppose, now i am in /home/coreadmin, now i have to check files from here, then how to mentation path in above script.

Thanks for your patience and help!

By "do whatever...." I mean put in your code to add to or update in CVS. Remember with CVS to use -kb flag for binary files when you add.

Hi Porter,

Here my problem not with CVS.

first of all i ahve to findout the binary and test files, for that you given below script, after running i am getting error "scrip.sh: syntax error at line 5: `do' unexpected"

find dir -type f | while read N
do
case "$N" in
*.txt | *.html )
do whatever with text file "$N"
;;
*.gif | *.jpg | *.jpeg )
do whatever with binary file "$N"
;;
* )
;;
esac
done

one more doubt is "while read N" means what? here N referring to what?

N is a variable to hold the name of the file.

Put the following as the first line of the script...

#!/bin/sh

I added #!/bin/sh, still i am getting below error :
scrip.sh: syntax error at line 7: `do' unexpected

I am executing the script from /home/coradmin

here
find dir -type f | while read N

dir: is the specific location where you need to place the directory

N: is the variable in which u need to place the type of file (.jpg;.txt etc)

replace the "do" within the case statement with "echo"

Finally i got whatever i am looking ...thankq so much porter