0

I have a directory with over 100 files that I have a list with a number that goes with each file. I want to run a for loop as such

numPairs="21 57 93... etc"
for filename in /directory/;
do
    $filename [numPairs[1]] > newfilename
done;

Is there a way to (say like in js, that's what I'm familiar with) call the numPairs item corresponding with the filename called in the for loop? Or would I be better creating another list with all of the filenames?

2
  • 3
    It's not clear to me what are you trying to do in this line: $filename [numPairs[1]] > newfilename Commented Aug 28, 2018 at 22:34
  • 1
    Is numPairs a string containing numbers delimited by whitespace? I'm also a bit befuddled by your code as it stands; please clarify. Commented Aug 28, 2018 at 22:36

1 Answer 1

1

Bash is like:

numbers="21 57 93"
while IFS=$'\t' read -r num file; do
    echo "num=$num file=$file"
done < <(paste <(printf "%s\n" $numbers) <(printf "%s\n" /directory/*))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.