I'm developing a program that outputs all the needed data from multiple files into columns. The problem is, my program can't align multiple output into a neat column.
This is my program functions:
#!/bin/sh
function findFile
{
while read -r LINE
do
find . -name "${LINE}" | grep "${LINE}" || echo "${LINE} not found"
done < /path/to/fnames.txt > /path/to/Files.txt
}
findFile
function grepFile
{
printf "ISA\t\tGS\tTrans\tSender ID\tReceiver ID\tINV PO Number\tASN PO Number\n"
fmt="%-16s%-8s%-8s%-8s%-24s%-9s%-12s\n"
while read -r LINE
do
gs=$(zgrep -oP 'GS.[^*]*.[^*]*.[^*]*.[^*]*.[^*]*.\K[\w\s\d]*' < $LINE | sort -u)
isa=$(zgrep -oP 'ISA.[^*]*.[^*]*.[^*]*.[^*]*.[^*]*.[^*]*.[^*]*.[^*]*.[^*]*.[^*]*.[^*]*.[^*]*.\K[\w\s\d]*' < $LINE | sort)
trans=$(zgrep -oP 'GE.\K[\w\s\d-]*' < $LINE | sort -u)
sender=$(zgrep -oP 'ISA.[^*]*.[^*]*.[^*]*.[^*]*.[^*]*.\K[\w\s\d-]*' < $LINE | sort -u)
receiver=$(zgrep -oP 'ISA.[^*]*.[^*]*.[^*]*.[^*]*.[^*]*.[^*]*.[^*]*.\K[\w\s\d-]*' < $LINE | sort -u)
bigponumber=$(zgrep -oP 'BIG.[\w\s\d-]*.[\w\s\d]*.[\w\s\d]*.\K[\w\s\d-]*' < $LINE | sort -u)
asnponumber=$(zgrep -oP 'PRF.\K[\w\s\d-]*' < $LINE | sort -u)
printf "$fmt" "${isa}" "${gs}" "${trans}" "${sender}" "${receiver}" "${bigponumber}" "${asnponumber}"
done < /path/to/Files.txt
rm /path/to/Files.txt
}
grepFile
output: Notice those numbers that are populating the left side of the screen? That's the PO Numbers.
ISA GS Trans Sender ID Receiver ID INV PO Number ASN PO Number
100000107 1107 1 2035735845 AMAZON 2IJW4EUG
100000018 1018 1 00116520M 5032337598 0082313829
100000096 1096 7 001165208 6111470100 0026-7684347-0551
0026-7684347-0557
0026-7684347-0580
0026-7684347-0587
0026-7684347-0589
0026-7684347-3803
0026-7684347-3804
100000580 1580 6 2035735845 TGTDVS 1310548379
1310570020
1310590953
1310596065
1310598477
1310609258
I want it to be like this: The same goes to INV PO Numbers
ISA GS Trans Sender ID Receiver ID INV PO Number ASN PO Number
100000107 1107 1 2035735845 AMAZON 2IJW4EUG
100000018 1018 1 00116520M 5032337598 0082313829
100000096 1096 7 001165208 6111470100 0026-7684347-0551
0026-7684347-0557
0026-7684347-0580
0026-7684347-0587
0026-7684347-0589
0026-7684347-3803
0026-7684347-3804
100000580 1580 6 2035735845 TGTDVS 1310548379
1310570020
1310590953
1310596065
1310598477
1310609258