Hi Everyone,
I am confused with the output of the input file and I am using below command in script to get the expected output.
Also I want to add another condition using logical AND (&&) in place of $2=="L"{$4=0-$4} as $2=="L" && $3=="L" {$4=0-$4} but I am getting some awk error.
Can someone please advise on this please?
Code:
cat $FILENAME |grep "^PL"|tr -d '\015'|sort -k1,2|nawk -F'|' 'BEGIN {OFS="~"}$2=="L"{$4=0-$4};$6=="COM"?$6="SHS":$6="FMT";{arr[$1"~"$5"~"$6]+=$4} END {for (i in arr) {print i,arr[i]}}'>$TEMPFILE
Input File
============
ISIN|BL|STATUS|QTY|SNAME|CLASS
PLKGHM000017|B|L|85000|KGHM|COM
PLPKO0000016|B|L|310000|PKO S.A.|COM
|B|L|0||
PLKGHM000017|L|L|35000|KGHM|COM
PL0000101937|B|L|100000|DS1110|GOV
|L|L|0||
PLKGHM000017|L|L|40000|KGHM|COM
PLPKO0000016|L|L|290000|PKO S.A.|COM
Present Output
==============
PL0000101937~B~L~100000~DS1110~FMT
PLKGHM000017~B~L~85000~KGHM~SHS
PLKGHM000017~L~L~-35000~KGHM~SHS
PLKGHM000017~L~L~-40000~KGHM~SHS
PLPKO0000016~B~L~310000~PKO S.A.~SHS
PLPKO0000016~L~L~-290000~PKO S.A.~SHS
PLPKO0000016~PKO S.A.~SHS~20000
PL0000101937~DS1110~FMT~100000
PLKGHM000017~KGHM~SHS~10000
Expected Output
==============
PLPKO0000016~PKO S.A.~SHS~20000
PL0000101937~DS1110~FMT~100000
PLKGHM000017~KGHM~SHS~10000