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.

1
  • How to print the the first line... sure, that guy was trying to do it with grep but anyway, the answers there should work for you too... Commented Nov 9, 2016 at 21:07

1 Answer 1

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.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.