I am working on a file with several columns as below
MO_NAME,FAULT_TYPE,CLASS,CODE1,CODE2,CODE3
RXOCF-101,BTS INTERNAL,FAULT CODES CLASS 2A,53,58
RXOCF-101,BTS INTERNAL,FAULT CODES CLASS 2B,24
RXOCF-101,BTS INTERNAL,FAULT CODES CLASS 2A,33
RXOCF-101,BTS INTERNAL,FAULT CODES CLASS 2D,57
RXOCF-102,OPERATOR CONDITION FAULT CODES CLASS 2B
By using awk I'm printing the output like this
awk -F',' '{print $1,$2,substr($1,1,5)"_"substr($3,19,20)$4,substr($1,1,5)"_"substr($3,19,20)$5' OFS="," file.txt
The output comes like this
RXOCF-101,BTS INTERNAL,RXOCF_2A53,RXOCF_2A58
RXOCF-101,BTS INTERNAL,RXOCF_2B24,RXOCF_2B
RXOCF-101,BTS INTERNAL,RXOCF_2A33,RXOCF_2A
RXOCF-101,BTS INTERNAL,RXOCF_2D57,RXOCF_2D
RXOCF-102,OPERATOR CONDITION,RXOCF_2B
I want to skip the columns whihc have null code or nothing in the code column. Please help to get this desired output