Вы можете использовать , а
, для
или до
, чтобы выполнить те же инструкции несколько раз раз. Я рекомендую вам создать функцию с вашим кодом и вызывать ее несколько раз, пока все значения не будут заменены.
Например, возможное решение, основанное на вашем примере:
threshold=5
eventperiod=3
replace_next_value() {
# Flag first occurrence with value over threshold and store the row number as a variable
# We need to check also that the input is a number to skip the Nans
startrow="$(awk '{print NR " " $1}' tmp.ascii | awk -v threshold=$threshold '$2 ~ /^[0-9]+$/ && $2 > threshold {print $1; exit}')"
[ -z "$startrow" ] && return 1 # No more rows to replace
endrow="$(($startrow + $eventperiod - 1))"
# Output range of rows as event
sed -n -e "$startrow,$endrow p" -e "$endrow q" tmp.ascii > output"$startrow".ascii
# Replace rows with Nan value
sed -i "${startrow},${endrow}s/.*/Nan/" tmp.ascii
return 0
}
# Call the function until it returns 1
while replace_next_value ; do continue; done