{
print_items(){
# print if there are 6 elements
if [ $# = 6 ]; then
echo "$@"
# print if the there are 7 elements, but merge element 5 and 7 before printing
elif [ $# = 7 ]; then
set -- "${@:1:4}" "${5}${7}" "${@:6:1}"
echo "$@"
fi
}
items=()
while IFS= read -r line; do
# Print items from previous line
print_items "${items[@]}"
# Get start position of first item
start_position=$(grep -o "^ *" <<< "$line" | wc -c)
# if start_position is 0 then create new array items with elements in the line
if [ $start_position = 0 ]; then
# when new line starts, print previous line
print_items "${items[@]}"
items=( $line )
# if start_position is not 0 then add the elements in the line to the existing items array
else
items+=( $line )
fi
# Print items
done < file
# print the last line
print_items "${items[@]}"
} | column -t
G00PFMA1 transition_readonly 2 cifs 0.0.0.0/0 any
G00PFMA7 transition_export_policy_1 1 nfs 10.58.91.134 sys
G00PFMA7 transition_export_policy_1 2 nfs bmczone.tsy.fm. sys
G00PFMA7 transition_export_policy_1 2 nfs bmczone.tsy.fm.hypovereinsbank.de sys
G00PFMA7 transition_export_policy_1 3 nfs inf01mz2 sys