1

I have a data set that has 1127 columns, I only need to know the header without listing the data itself in each column.

For example, data as

name age
m     33
A     26

I need a code in UNIX that will give me the header, which in this case is: name, age.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255

1 Answers1

6

Using head

head -n 1 filename
# OR
cat filename | head -n 1

Using Sed

sed 1q filename
# OR
sed -n 1p filename
# OR
cat filename | sed 1q

Using Awk

awk NR==1 filename
# OR
cat filename | awk 'NR==1'

Using ex

ex -sc '1p|q' filename

Using more

more -n2 -pq filename
# OR
cat filename | more -n2 -pq

Notes

In all of the above commands, cat filename | is intended as a stand-in for any command that produces textual output, showing how to use these tools in a pipeline.

All commands use only features listed in POSIX Specifications.

Wildcard
  • 36,499