1

So basically I need to run a command lets say $ exampleCommand var1_1 and on completion of this command run $ exampleCommand var1_2 then with var2_1 etc.... I am running this on 50-60 files each at 90+gb so it doing this manually is not possible and I have never tried to automate something like this. Id appreciate some tips on how to go about doing this. I think I create a .sh file and then run it on the server im working on?

  • Does it matter if the command succeeds or fails? – Jeff Schaller Sep 13 '17 at 23:38
  • It doesn't. I need it to move forward regardless, but the runs shouldn't fail at all since everything has been tested and the data checked endlessly – Ayedu Sep 14 '17 at 20:20
  • Are these var1_2 combinations existing filenames? Or numeric combinations that you need to generate based on ...? – Jeff Schaller Sep 15 '17 at 2:17
2

This should point you in the right direction:

$ for i in {1..3}; do for j in {x..z}; do echo ${i}_${j}; done; done
1_x
1_y
1_z
2_x
2_y
2_z
3_x
3_y
3_z
|improve this answer|||||
  • 1
    +1 for using echo statements to see what commands your code is generating before actually executing the commands. – Matt Obert Sep 13 '17 at 23:25
0

The question you ask is a bit to global, and there are a lot of ways to automate specific tasks. The issue often comes in so many different file names, or regex match patterns. Please backup files before even running any script.

Just to get you going in a direction, see examples:

array=(file1 file2 file3)
for i in "${array[@]}"; do
    echo "$i"
done

user@workdir: # cd /dir && ls > ../files.list

main() {
    local list='/workdir/files.list'
    for item in $(cat "$list"); do
        func_read "$item"
    done
}

func_read() {
    local var="$1"
    [[ ! -d "$var" ]] && \
        while read -r line; do
            echo "$line"
        done < "$var"
}
main
|improve this answer|||||

Not the answer you're looking for? Browse other questions tagged or ask your own question.