1 year ago
#368395
David Smerdon
Moving and editing multiple text files in a loop in python
I have a directory with 71 folders named lifecyc1, lifecyc2, ..., lifecyc71. Each folder contains a folder /data
and a text file script1.sh
. The script is short:
#!/bin/bash
#PBS -A UQ-BEL-Economics
#PBS -N lifecyc1
#PBS -l select=1:ncpus=22:mem=16gb
#PBS -l walltime=15:00:00
I need to do two things:
- For each folder i called lifecyci, change the third line of the script script1.sh in that folder from
#PBS -N lifecyc1
to#PBS -N lifecyci
and rename the file toscripti.sh
, wherei
is the folder number from 1 to 71. E.g. for folder 2, edit the line to#PBS -N lifecyc2
and rename the file toscript2.sh
. - Move files named
datai.pgn
from a directory PATH into the correspondinglifecyci/data
, wherei
is the folder number. E.g. movePATH/data1.pgn
intolifecyc1/data
, movePATH/data2.pgn
intolifecyc2/data
, etc.
I would like to do this in python, or in Terminal if that is easier.
python
loops
rename
batch-processing
edit
0 Answers
Your Answer