You expect a ksh
solution.
As ksh
is sh
-compatible a sh
script is fitting too. Additionally it maximizes portability:
#!/bin/sh
# Expects the data file as first parameter.
for input in $(cat $1); do
header="${header}|${input%|*}"
data="${data}|${input#*|}"
done
echo ${header#*|}
echo ${data#*|}
If you prefer to use a pipe the suggestion of @Fravadona is the script for you:
#!/bin/sh
# Accepts the data from pipe
while IFS='|' read -r key value; do
header="${header}|${key}"
data="${data}|${value}"
done
echo ${header#*|}
echo ${data#*|}