Help with data manipulation script

Y,T,,H05,6,6,0,0 -> TH05_6
D,5,BT,B -> BT_KIOSK
P,KQC222 -> KQC222
G,B,2 -> BRANI_GATE_2

fileA

TPM658 Y,T,,H05,6,6,0,0
TPM110 D,5,BT,B
TPM136 P,KQC222
TPM180 P,BQC913
TPM575 Y,B,,T05,14,14,0,0
IPM760 G,B,2
TPM011

I need to use second column
$1,$2,$3,$4.....
if first char =='Y' then obtain $2,$4,'',$6
else if first char =='D' then obtain $3
'KIOSK'
else if first char =='P' then obtain $2
else if first char =='G' then BRANI_GATE_2
else null
getting the result:

TPM658 TH05_6
TPM136 KQC222
TPM180 BQC913
TPM575 BT05_14
IPM760 BRANI_GATE_2
TPM011

Hi guys, need an approach guide to the problem. I dont know how to start :(. Thanks.

Is this homeworks ?

nope I am doing intern and my boss requested me to do it ...

 sort -k2 file2 -o file2
awk -F"," 'NR==FNR{a[$1]++;next} {char=substr($1,length($1),1);if(a[char] ){ if (char == "Y") {
print $2,$4"_"$6} else if (char == "D") { print $3"_KIOSK" } else if  (char == "P" ) { print $2} else if (char == "G"){ print "BRANI_GATE_2" } else {print }}
}' file1 file2
1 Like

will do work on your script to find the problem but thanks for a good start

Shell version:

while IFS=' ,' read label f1 f2 f3 f4 f5 f6 f7
do
  case $f1 in
    Y) res=${f2}${f4}_${f6} ;;
    D) res=${f3}_KIOSK      ;;
    P) res=$f2              ;;
    G) res=BRANI_GATE_2     ;;
    *) res=                 ;;
  esac
  printf "%s\n" "$label $res"
done < infile
1 Like

OMG!!! I LOVE YOU!!!!

I dont know what is the miraculous script u have written but this is superBBBBB.....

1 Like