You are not logged in.
I cannot remember my basic bash. Please help.
Given a set of files, file_#.text, where # is selected from [ABCDEFGHJKLMNPQ], a closed set of known letters,
how do I write a loop executing once per letter?
I would check my loop by the statement
echo process1 file_#.text otherfile_#.textto make sure the substitution is correct,
(where what will execute when finished is "process1 file_#.text otherfile_#.text").
Last edited by OrigBitmancer (2020-07-09 01:56:08)
Offline
for x in *.text; do the_thing "$x"; doneOffline
JWR, the simple for loop would not acheive the main goal of having that letter in both arguments to the process.
The direct answer to your question is this:
for N in A B C D E F G H J K L M P Q; do
process1 file_${N}.text otherfile_${N}.text
doneBut if you are not exactly sure what the letters are, or if they may change, the following more flexible approach might be better:
for fname in file_*.text; do
process1 $fname otherfile_${fname#file_}
doneEDIT: looking back on this, the command in my second loop is pretty silly, this would have the same result:
process1 $fname other${fname}Last edited by Trilby (2020-07-09 02:12:50)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
JWR, the simple for loop would not acheive the main goal of having that letter in both arguments to the process.
The direct answer to your question is this:
for N in A B C D E F G H J K L M P Q; do process1 file_${N}.text otherfile_${N}.text doneBut if you are not exactly sure what the letters are, or if they may change, the following more flexible approach might be better:
for fname in file_*.text; do process1 $fname otherfile_${fname#file_} done
Thank you very much! Your first solution did the trick. It was a mistake in my punctuation in my source.
Not quite sure why the other reply was unhelpful?
Last edited by OrigBitmancer (2020-07-09 01:56:41)
Offline
Not quite sure why the other reply was unhelpful?
I had misunderstood your requirements; I thought you just wanted to loop over a set of files.
Offline