I'm operating on large amounts of data, and have a protocol involving several scripts. I launch it separately for each input file, simply swapping filename
in text file containing the command. I would like to know if it's possible to automate it for all files with certain extensions, when for x in ...
is used in the command.
Example of what I have now
mkdir filename.file && for f in *.different_file; do [[ -n $(awk 'NF{i++} END {if (i<14) print FILENAME}' "$f") ]] && rm "$f" ;done
and the functionality I would like to have:
for x in location/*.file do; mkdir $x && for f in *.different_file; do [[ -n $(awk 'NF{i++} END {if (i<14) print FILENAME}' "$f") ]] && rm "$f" ;done ;done
there would be more loops inside the main loop, but not stacking anymore.
How can I achieve something like that?
EDIT: Some more info on what I want, pardon my unprofessional language:
I would like to have two variables working inside two loops, one inside another. I believe using nested loops as suggested by @Lety might be the best solution although it will take some time to test it.
Some more commands I'm using to visualize the issue:
mkdir filename.file && for i in *.file2; do program /filename.file/filename.file $i> $i.filename.file.out ; done && for f in *.file.out; do [[ -n $(awk 'NF{i++} END {if (i<14) print FILENAME}' "$f") ]] && rm "$f" ;done && for i in *.file.out; do grep -v '^#' $i >> $i.trim; done
I would like to have filename.file set as a variable that would be the same for all loops:
for x in *.file do; mkdir $x && for i in *.file2; do program /$x/$x $i> $i.$x.out ; done && for f in *.file.out; do [[ -n $(awk 'NF{i++} END {if (i<14) print FILENAME}' "$f") ]] && rm "$f" ;done && for i in *.file.out; do grep -v '^#' $i >> $i.trim; done; done
I hope this clarifies a bit. I will investigate nested loops in bash script, another difficulty is this it has to work for cygwin as well, but I guess it shouldn't matter as far as the commands are right.
; if [ mkdir $x ] then ...(for statement here)..fi
ormkdir $x; if [ $? == 0 ] then ...(for statement) ...fi
. Let me know if this works. I'll post as answer