Perform a set of actions for a specific file type


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perform a set of actions for a specific file type
# 1  
Old 06-14-2009
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
./APBS/share/tools/manip/coulomb ./$1.pqr >> ./$1.coulomb.txt

#polar calculations
./psize.py $1.pqr >> $1.psize.txt
./apbs-create.out $1
apbs $1.apbs.in | tee $1.apbs.out

That $1 argument that you see is the name of a PDB file. For example, ./script XXXX would mean XXXX.pdb. The thing is, the program works when the script is ran for each PDB file individually, but it is rather time consuming. I would rather create some sort of For... loop that scans every file in a specific folder and runs this set of commands if it is a .PDB file.

I know that you can use $ echo "file.txt" | awk -F . '{print $NF}' to print out the extension, and I would imagine that I can add an If... statement to test whether that output is PDB, but I don't know how to get the shell to do this for every file in the folder. I'm ridiculously new to scripting and my previous experience with programming is helping me very little.

I was thinking about using dir to create a list of all .PQR files, i.e.
dir *.pdb > file_list.txt and then using this command that I found online echo $(basename $F | awk -F. -v OFS=. '{$NF=""; sub("[.]$", ""); print}') to extract just the file name. The thing is, with this I would have to read a file line by line in the script and I don't know how to do this yet. I will try this and if it works I will update the thread with the results. *crosses fingers*

I apologise in advance if this question has already been addressed and I overlooked it.

EDIT:
I actually feel rather foolish, because I found this: https://www.unix.com/shell-programmin...file-type.html almost immediately after posting this thread. It looks like my answer was in fact already there. I apologise for that.

Last edited by oehtus; 06-14-2009 at 04:31 PM..
# 2  
Old 06-15-2009
Here's how I did it, in case anyone is interested.

for F in `dir *.pqr`
do
filename=`basename $F .pqr`
echo $filename
#coulombic calculations
/scratch/XXXX/APBS/share/tools/manip/coulomb ./$filename.pqr >> ./$filename.coulomb.txt

#polar calculations
./psize.py $filename.pqr >> $filename.psize.txt
./apbs-create.out $filename
apbs $filename.apbs.in | tee $filename.apbs.out

done
# 3  
Old 06-15-2009
i see you use a Python script psize.py. For every file found, you call this script and some other tools, which is very inefficient. If I were you , i would do everything in that Python script.
eg
Code:
import os,sys,glob
coulomb = os.path.join("/","scratch","XXXX","APBS","share","tools","manip","coulomb")
for files in glob.glob("*.pqr"):
    filename = files[-4:] #equivalent to your basename command
    fin,fout = os.popen4(couloumb)
    <psize.py code here>
    < and the rest....>
    ......
    ........

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search for specific file type in subdirectory with multiple folders

I have a directory that is in the below order (the --- is not part of the directory tree, only there to help illustrate: DATE --- main level Folder1 --- level under DATE plugin_out --- level under Folder1 variantCaller_out.40 --- level under plugin_out 001,002,003 --- level under... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

Problem in Pattern-Specific Actions in awk

Hi i am in learning phase of unix i am able to understand basic of awk but not able to understand Pattern-Specific Actions in awk below is the snippet . awk ' / *\$*\. */ { print $1,$2,$3,"*"; } / *\$0\. */ { print ; } ' fruit_prices.txthere i am not getting the use of wild card. what... (4 Replies)
Discussion started by: scriptor
4 Replies

3. Shell Programming and Scripting

how to count how many subdirectory containing more than a certain number of specific file type

hi I want to write a script which count the number of subdirectories in the current root directory that contain more than a specified number of files of a specific type. Is there an easy way to do this? Thanks Robert (2 Replies)
Discussion started by: piynik
2 Replies

4. Shell Programming and Scripting

perform actions at specific locations in data frame

Hi everyone, I got a data frame like the one below and and would like to do the following: Ignore the first 3 rows and check in all following rows the second position. If the value is >500, subtract 100. Example DF: ABC 22 DE 12 BCD 223 GH 12 EFG 2104 DH ... (4 Replies)
Discussion started by: TuAd
4 Replies

5. Shell Programming and Scripting

perform some operation on a specific coulmn starting from a specific line

I have a txt file having rows and coulmns, i want to perform some operation on a specific coulmn starting from a specific line. eg: 50.000000 1 1 1 1000.00000 1000.00000 50000.000 19 19 3.69797533E-07 871.66394 ... (3 Replies)
Discussion started by: shashi792
3 Replies

6. UNIX for Dummies Questions & Answers

Print folder size ordered by pattern value of specific file type :-) ! challenge !

Hello dear unix command line friends ! I'm looking for a simple combinaison of ls & awk (maybe grep) to print: list of folders of a directory |_ ordered by size like what I have with $ du -sk ./* | sort -rn printing that result: 8651520 ./New Virtual Machine_1 8389120 ./Redhat ... (1 Reply)
Discussion started by: holister
1 Replies

7. Shell Programming and Scripting

Set default app for file type on Mac

Hi there, We have 2 apps on our customers machines that can both open files with the same file extension. Is there any way via shell commands to set which application should be the default? Essentially, I'm hoping to replicate Get Info > Open With > Change All using a shell script, but I just... (0 Replies)
Discussion started by: davewg
0 Replies

8. UNIX for Advanced & Expert Users

How to perform Grep on many Gzip files, Searching for Specific information

Hello, I am wondering if you can assist with my question and ask kindly for this. I have a number of files that are listed as file1.gz through file100.gz. I am trying to perform a grep on the files and find a specific date that only resides within within one of the files. There are... (3 Replies)
Discussion started by: legharb
3 Replies

9. AIX

Script to perform some actions on multiple files

I have this Korn script that I wrote (with some help) that is run by cron. I basically watches a file system for a specific filename to be uploaded (via FTP), checks to make sure that the file is no longer being uploaded (by checking the files size), then runs a series of other scripts. The... (2 Replies)
Discussion started by: heprox
2 Replies

10. Shell Programming and Scripting

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... (1 Reply)
Discussion started by: kristy
1 Replies
Login or Register to Ask a Question