'I'm looking for a way to add headers to the output .csv file when generated

I'm looking for a way to add headers to the output .csv file when generated. Also, I'm trying to figure out what the [0][0] is after each tag value, if someone can assist with that too I would be grateful. Thank you

ec2 describe-instances --output text --query 'Reservations[].Instances[].[InstanceId, InstanceType, ImageId, State.Name, LaunchTime, Placement.AvailabilityZone, Placement.Tenancy, PrivateIpAddress, PrivateDnsName, PublicDnsName, [Tags[?Key==Name].Value] [0][0], [Tags[?Key==purpose].Value] [0][0], [Tags[?Key==environment].Value] [0][0], [Tags[?Key==team].Value] [0][0] ]' > instances.csv



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source