Skip to content

Instantly share code, notes, and snippets.

@mikybars
Created September 17, 2021 14:52
Show Gist options
  • Save mikybars/2628fa6e09f2343f0895df10811783aa to your computer and use it in GitHub Desktop.
Save mikybars/2628fa6e09f2343f0895df10811783aa to your computer and use it in GitHub Desktop.
[Print field names along their indexes from tabular data] Most useful for big log files #csv #awk
awk '(NR==1) {for (i=1;i<=NF;i++) print i ": " $i}' <data.csv
# 1: date
# 2: time
# 3: x-edge-location
# 4: sc-bytes
# 5: c-ip
# 6: cs-method
# 7: cs(Host)
# ...
# print date, time and ip
awk 'NR > 1 { OFS=" | "; print $1,$2,$5 }' <data.csv
# 2019-12-04 | 21:02:31 | 192.0.2.100
# 2019-12-04 | 21:02:31 | 192.0.2.100
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment