Ответ аналогичен ответу Тора, но сохраняет строку до ее завершения:
awk -F, '
$1 != "" {if (record) print record; record = $0}
$1 == "" {record = record "|" $NF}
END {if (record) print record}
' file
Если вы хотите использовать bash, вы можете сделать
lines=()
while IFS= read -r line; do
if [[ ${line:0:1} == "," ]]; then # the line starts a comma
lines[-1]+="|${line##*,}" # strip the commas and append to
# the last element of the array
else
lines+=("$line") # append the line to the array
fi
done <<"$1"
printf "%s\n" "${lines[@]}"
ABC,SSSD,12345,NSS,12345,xxx,TS11|TS21|TS22|BS26|GPRS
ABC,SSSD,12356,NSS,12356,xxx,TS11|TS21|TS22|GPRS|BS26