Shell Script to Run a python code with two different folders of The Same Numbered Files -


i have 2 folders , each contains files has same numbering systems part of file name. example,

folder 1 has:

  001file_read.txt, 002file_read.txt, until 650file_read.txt 

folder 2 has:

  001filtr.tsv, 002filtr.tsv, until 650filtr.tsv 

i want run python code using shell script runs following:

 python my_python_prog.py 001file_read.txt  001filtr.tsv 

the problem because have huge number of files of both folders. want find way run command once automatically run file001 folder1 file001 folder2 , file002 folder1 file002 folder2 , on until file650 of both folders. how can using shell script?

thanks lot in advance,

if have bash, use script this:

#!/bin/bash   in {001..650};     file_read=dir1/${i}file_read.txt     file_filtr=dir2/${i}filtr.tsv     if [[ -f $file_read ]] && [[ -f $file_filtr ]];         python my_python_prog.py "$file_read" "$file_filtr"     fi done 

this loops through numbers 000 650, checks both of 2 files exists , executes python command if do.

if don't have bash, can achieve same thing making few changes:

#!/bin/sh  while (( ++i <= 650 ));     n=$(printf '%03d' "$i")     file_read=dir1/${n}file_read.txt     file_filtr=dir2/${n}filtr.tsv     if [ -f "$file_read" ] && [ -f "$file_filtr" ];         python my_python_prog.py "$file_read" "$file_filtr"     fi done 

alternatively, modify python script, perform loop within it, , use os.path.isfile() verify both files exist. advantage of approach don't call script 650 times.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -