Something like this:
Code:
longitude= altitude=
while
read -r line &&
[ -z "$longitude" -o -z "$altitude" ]
do
case $line in
( *longitude* )
longitude=$line
;;
( *altitude* )
altitude=$line
esac
done < <( command_to_process )
printf "%s\n" "$longitude" "$altitude"
This runs the "command_to_process" once,
and reads its output until longitude and altitude occurs.
The alternative is to run a command many times, each time checking if the expected output occurs.