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.


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


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.