Score:1

How to generate multiple files in sequence with data in sequence?

gy flag

I have to create 50 files in sequence labelled r01.inp to r50.inp and in each file I need this text in sequence as well.

#!/bin/bash
abc2 r01.inp > r01.log

I used echo and touch to create the 50 files with same data but I still have to manually change r01.inp > r01.log to match the file name. Is there any way I can generate multiple files and the data inside it is also in a sequence i.e. r01.inp has abc2 r01.inp > r01.log while r02.inp has abc2 r02.inp > r02.log in it and so on.

Score:2
us flag

From google bash loop padded to StackOverflow How to zero pad a sequence of integers in bash so that all have the same width? I ended up with:

for i in $(seq -f "%02g" 1 50)
do
    echo "#!/bin/bash
abc2 r$i.inp > r$i.log" > r$i.inp
done

This will produce r01~r50.inp files and each file will contain the #!/bin/bash hashbang and the abc2 r##.inp > r##.log line as requested.

hr flag
You could also use `seq -w 1 50` or just use a bash *brace expansion* `{01..50}`
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.