How do I read the first line of a file using cat?
You don't, use head
instead.
head -n 1 file.txt
You could use cat file.txt | head -1
, but it would probably be better to use head directly, as in head -1 file.txt
.
There are many different ways:
sed -n 1p file
head -n 1 file
awk 'NR==1' file
You don't need cat
.
head -1 file
will work fine.