Em awk
, você poderia fazer:
$ awk '{
a[$1][$2][$3] ?
a[$1][$2][$3]=a[$1][$2][$3]"\n\t\t\t"$4 :
a[$1][$2][$3]="\t\t\t"$4 ;
}
END{
for(cont in a){
printf "%s\n", cont;
for(count in a[cont]){
printf "\t%s\n", count;
for(city in a[cont][count]){
print "\t\t"city"\n"a[cont][count][city]
}}}}' file
EUROPE
FRANCE
TOULOUSE
TL-654
PARIS
IV-122
AV-112
IF-111
XX-190
AMERICA
USA
NEW_YORK
AB-100
VF-200
XY-243
LOS_ANGELES
UH-198
CANADA
VANCOUVER
UT-871
UT-872
UT-873
TORONTO
UT-876
UT-877
MEXICO
MEXICO
OU-098
MONTERREY
OU-099
OU-100
Em Perl:
perl -lane 'push @{$k{$F[0]}{$F[1]}{$F[2]}},"\t\t\t".$F[3];
END{
for $cont (keys(%k)){
print "$cont";
for $coun (keys(%{$k{$cont}})){
print "\t$coun";
for $city (keys(%{$k{$cont}{$coun}})){
print "\t\t$city\n",
join "\n",@{$k{$cont}{$coun}{$city}}
}}}}' file
EUROPE
FRANCE
PARIS
XX-190
XX-190
TOULOUSE
TL-654
AMERICA
USA
NEW_YORK
XY-243
XY-243
LOS_ANGELES
UH-198
MEXICO
MONTERREY
OU-100
OU-100
MEXICO
OU-098
CANADA
VANCOUVER
UT-873
UT-873
TORONTO
UT-877
UT-877