actions based on file type


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting actions based on file type
# 1  
Old 11-19-2001
actions based on file type

Hello. I am trying to put together a ksh script that will perform actions on files based on what type they are. The types would be compressed, zipped, or PCL. I think my test conditions are ok, but I'm a little unsure about how to put it all together. I've come up with this, which does not work...

for A in `ls -1 $DIR1`
do
if [ `file $A | grep -c 'ZIP archive'` -ge 1 ]; then
mv $A $ZIPDIR;
if [ `file $A | grep -c 'compressed'` -ge 1 ]; then
mv $A $ZDIR
if [ `grep -c 'LANGUAGE=PCL'` -ge 1 ];then
mv $A $PCLDIR
fi
fi
fi
done


I get the feeling that this is fairly sloppy and there MUST be a way to do this better (and works).
# 2  
Old 11-19-2001
I think your "if" logic needs to be cleaned up. You should probably use "elif" instead of the "if" after the first time you use it. Then you only need one fi at the end. Or, in this case, you may want to use "case" instead of "if".
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Count occurrence of string (based on type) in a column using awk

Hello, I have a table that looks like what is shown below: AA BB CC XY PQ RS AA BB CC XY RS I would like the total counts depending on the set they belong to: if search pattern is in {AA, BB, CC} --> count them as Type1 | wc -l (3 Replies)
Discussion started by: Gussifinknottle
3 Replies

2. Shell Programming and Scripting

Combining sed actions

Let's say I have an input file looking like: ID1 1 5 6 8 ID2 1 4 5 7 I'm trying to formulate a loop that can combine these actions: - If the line begins with a letter: replace the '\ n' after a field containing characters with a '\ t' (sed 's / \ n / \ t / g' ) - If the line... (2 Replies)
Discussion started by: dovah
2 Replies

3. Shell Programming and Scripting

Shell script to read file and check file type

Hi, I have a file with few values in it. I need script help to read file line by line and check: 1/if it's a file (with extension eg .java .css .jar etc ) or 2/if it's a file without extension and treat it as a directory and then check if the directory exists in working copy else create one... (6 Replies)
Discussion started by: iaav
6 Replies

4. Shell Programming and Scripting

[solved] File type error (not a regular file)

Hi friend, i have written script as below to check the file existance. but i got error path="/k/p1100/users/jewel/Output" FILENAME=`ls -lrt $path/*HT|tail -1|cut -d "/" -f 8` if ; then echo "$FILENAME is available " chmod 755 $path/$FILENAME /usr/bin/scp... (0 Replies)
Discussion started by: Jewel
0 Replies

5. Shell Programming and Scripting

Perform a set of actions for a specific file type

Hello, I have a problem that I'm having quite a bit of trouble with. I am trying to create a script that performs a specific sequence of actions for a file of a specific type. This is an abbreviated version of my basic script: #!/bin/sh #coulombic calculations... (2 Replies)
Discussion started by: oehtus
2 Replies

6. Programming

array type has incomplete element type

Dear colleagues, One of my friend have a problem with c code. While compiling a c program it displays a message like "array type has incomplete element type". Any body can provide a solution for it. Jaganadh.G (1 Reply)
Discussion started by: jaganadh
1 Replies

7. HP-UX

Auditing User's actions

Hi all I hope to find what i'm looking for in this forum as said in the topic i want to track user's actions on the system. i mean also the action of moving or removing files. I have an HP 9000 with HP UX 11i. the users log on the HP from a terminal window under WIndows XP Thx (3 Replies)
Discussion started by: Timberland
3 Replies

8. Shell Programming and Scripting

Help with simple scripting actions

Hi, I am a beginner in unix shell scripting. I wanted simple information like 1- How to know what are the number of command line options given for the script file? 2- How to check if a variable value is interger or string? 3- How to use awk to replace value of a variable For example I... (5 Replies)
Discussion started by: Nads
5 Replies
Login or Register to Ask a Question