value=`awk '!a[$1]++' check_remove_dupli_1st | awk '{print $1}'`
set -A array_value $value
for i in ${array_value[@]}
do
echo "catagory" $i
while read line
do
str=`cat check_remove_dupli_1st | grep "$i" | awk '{print $2}'`
set -A array_str $str
for j in ${array_str[@]}
do
echo item $j
done
echo "ok"
break;
done < "check_remove_dupli_1st"
done
if variable cat != $1 then
if variable cat is not empty then
print "ok" and RS
end if
variable cat = $1
print "category " and $1
end if
print "item" and $2
END {print "ok"}
p will not be equal to field1 in 2 condition, that is
1 ---> when awk read 1st line, p is not set
2 ---> p is set, meaning we already read line before but field1 of current line is not equal p (assume p is previous line field1)
NR == 1 ? ---> if the line read by awk is 1st line then we are interested print only,
string "category"OFS (default is space) and column1 field $1
else, line read by awk is not first one, then print
string "ok" record separator RS (default is "\n") and print string "category"OFS (default is space) and column1 field $1
print "item",$2 ---> print string "item" and field2 $2 , with output field separator being default (space)
p=$1 ---> set p is field1 read from current line, which will be used to compare with next line again $1!=p
END{print "ok"} ---> The code in this block will be executed after executing all code, in short this is the last code going to execute in program, in current program it prints string "ok"