2 years 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 lifecyc1to#PBS -N lifecyciand rename the file toscripti.sh, whereiis the folder number from 1 to 71. E.g. for folder 2, edit the line to#PBS -N lifecyc2and rename the file toscript2.sh. - Move files named
datai.pgnfrom a directory PATH into the correspondinglifecyci/data, whereiis the folder number. E.g. movePATH/data1.pgnintolifecyc1/data, movePATH/data2.pgnintolifecyc2/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