Shell script for the below operation :
File "A" contains :
SEQ++1'
MOA+9:000,00:ABC'
RFF+AIK:000000007'
FII+PH+0170++AA'
NAD+PL+++XXXXXXXXXXX XXXXXXX XX++XXX XXXX XXXX X.X. XXXXXXXXX+++NL'
SEQ++2'
MOA+9:389,47:ABC'
RFF+AIK:02110300000008'
FII+PH+0PSTBNL2A:25:5+BB'
NAD+PL+++************************++********************+++NL'
SEQ++3'
MOA+9:3086,55:DDD'
RFF+AIK:00009'
FII+PH+0348932928++GG'
NAD+PL+++XXX++XXX XXXX XXXX X.X. XXXXXXXXX+++NL'
Need to fetch the details from the above file "A" and put them in file "B" in the below format :
payment file | Amount | Ref | Account No
1 9:000,00:ABC' 000000007' 0170\+\+AA
2 9:389,47:ABC' 02110300000008' 0PSTBNL2A:25:5\+BB'
The columns can be tab delimited.
I was able to do it in step wise using sed...have anyone done this in this way?
Thanks....
Digby
2
There is probably a much much easier way to do this, but here's how I would do it given my limited knowledge.
perl -pe 's/SEQ/SEQSEQ/' < $yourfile |\
perl -pe 's/\w\w\w//' | perl -pe 's/\n/::::/' |\
perl -pe 's/SEQ/\n/g' | perl -pe 's/^\+\+//' |\
perl -pe's/::::/\t/g' | perl -pe 's/\t\+/\t/' |\
perl -pe 's/\+AIK\://' | perl -pe 's/\+PH\+//' |\
awk '{print $1,$2,$3,$4}'
Hi Digby,
Thanks very much for the reply but I was watching out for some unix shell script stuff for the solution.
Can anyone help in this....using shell script.
Thanks...
ce9888
4
printf "%-5s %-15s %-20s %-20s \n\n" "File" "Amount" "Ref" "Account No" > fileB
while read line
do
if [ `echo $line | grep SEQ` ]
then
f1=`echo $line | cut -d"+" -f3- | cut -d"'" -f1`
fi
if [ `echo $line | grep MOA` ]
then
f2=`echo $line | cut -d"+" -f2-`
fi
if [ `echo $line | grep RFF` ]
then
f3=`echo $line | cut -d":" -f2-`
fi
if [ `echo $line | grep FII` ]
then
f4=`echo $line | cut -d"+" -f3-`
printf "%-5s %-15s %-20s %-20s \n" $f1 $f2 $f3 $f4
fi
done < textfile >> fileB
cat fileB
File Amount Ref Account No
1 9:000,00:ABC' 000000007' 0170++AA'
2 9:389,47:ABC' 02110300000008' 0PSTBNL2A:25:5+BB'
3 9:3086,55DD' 00009' 0348932928++GG'
Hope this helps:
sed "s/^NAD.*$//" FileA | tr -d "\n" | sed "s/SEQ++/\n/g;s/MOA+/,/g;s/RFF+AIK:/,/g;s/FII+PH+/,/g;" | sed '1d'
Changes keywords into a comma ","
So that output will be:
$ sed "s/^NAD.*$//" FileA | tr -d "\n" | sed "s/SEQ++/\n/g;s/MOA+/,/g;s/RFF+AIK
:/,/g;s/FII+PH+/,/g;" | sed '1d'
1',9:000,00:ABC',000000007',0170++AA'
2',9:389,47:ABC',02110300000008',0PSTBNL2A:25:5+BB'
3',9:3086,55DD',00009',0348932928++GG'