If you mean you need to pass each directory into stdin:
convAll ()
{
while read line
do
echo -e "$line\n0" | trjconv -s run.tpr -f run.xtc -pbc mol -ur compact -o unwrap
done
}
ls | grep -E 'us_-?[0-9]\.[0-9]+' | convAll
# NOTE: There's probably an even shorter one-liner version of this that uses `xargs`, but
# I'll leave that as an exercise to the reader.
If you mean you need to pass each directory as an additional argument:
ls | grep -E 'us_-?[0-9]\.[0-9]+' | tr '\n' '\0' | \
xargs -0 -n 1 trjconv -s run.tpr -f run.xtc -pbc mol -ur compact -o unwrap
If you mean you need to cd
into each directory:
convAll ()
{
while read line
do
(\
cd "$line" && \
trjconv -s run.tpr -f run.xtc -pbc mol -ur compact -o unwrap || \
echo "Command failed for '$line'." >&2 \
)
done
}
ls | grep -E 'us_-?[0-9]\.[0-9]+' | convAll
for all subdirectories
, do you mean that you need to cd into all these directories and run the command while in each directory, or that you need to have the name of one of those directory onstdin
for each run, or that you need to provide one of the directories as an argument each time?foo/us_17.42
? Oh, also, can both of the numbers have multiple digits, as inus_1234.5678
?