0

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:

  1. 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 to scripti.sh, where i is the folder number from 1 to 71. E.g. for folder 2, edit the line to #PBS -N lifecyc2 and rename the file to script2.sh.
  2. Move files named datai.pgn from a directory PATH into the corresponding lifecyci/data, where i is the folder number. E.g. move PATH/data1.pgn into lifecyc1/data, move PATH/data2.pgn into lifecyc2/data, etc.

I would like to do this in python, or in Terminal if that is easier.

David Smerdon
  • 59
  • 1
  • 6
  • 1
    To edit files in place use `sed -i` (see https://linux.die.net/man/1/sed) and to move the files just `mv` – Diego Torres Milano Apr 03 '22 at 02:08
  • You’ll probably get farther on SO if you ask one targeted question at a time. E.g. you might ask which approach (e.g. Python script, Bash script, etc.) from a few options is recommended given your specific requirements (e.g. a tight deadline, your own familiarity with the approaches, etc.). Or you might pick one and ask questions to help you get unstuck when you get stuck (e.g. “How do I replace lines of text in a file in Python”—just making something up). This question is too vague and is likely to get closed in its current form. – bob Apr 03 '22 at 02:14
  • There are an abundance of tools and ways to do this: perl, python, bash, octave, ruby, etc. will give you a way to do this. Asking which way is best is asking for opinions, which tends to fall outside of scope of SO. I don't know that any way is necessarily wrong, I would pick a language you are familiar with, make a back-up of your file structure, and try to learn how to do it. Then if you have particular questions you can ask those as you go. – ramzeek Apr 03 '22 at 04:23

0 Answers0