简体   繁体   中英

loop in bash/python to call a command including name fixation

I have a line of code that works on a single file:

sextractor ABC347583_ima.fits -CATALOG_NAME ABC347583_ima.cat

this piece of line takes the .fits file and creates a catalog file with the same name but .cat extension

Now, I have over 100+ .fits files(All my files start with the name ABC then numbers and end with _ima) and I would like to make a bash/python script that will read the .fits files 1 by 1 and execute the above code with the corresponding file names as input & output.

Basicly ABC347583_ima.fits , ABC57334_ima.fits etc. will enter and ABC347583_ima.cat , ABC57334_ima.cat etc. will be created.

This is beyond my limited knowlegde and what I only know about this is to use the code with

for i in `cat files`
echo $i

However, this does not exactly match with the command line because of both input & output. Any suggestions about how to pass this will be appreciated.

To iterate in python over all files in a dictonary use os.listdir().

Then you can loop over the filenames. in the "callthecommandhere" function you can parse the filenames and read the file content and write a new file. I hope I understand you right and that is a help for you.

Like so:

import os
for filename in os.listdir('dirname'):
     callthecommandhere(blablahbla, filename, foo)

Br christoph

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM