How do I read the first line of a file using cat
?
You don't need cat
.
head -1 file
will work fine.
You could use cat file.txt | head -1
, but it would probably be better to use head directly, as in head -1 file.txt
.
Use the below command to get the first row from a CSV file or any file formats.
head -1 FileName.csv
cat
alone may not be possible, but if you don't want to use head
this works:
cat <file> | awk 'NR == 1'
You don't, use head
instead.
head -n 1 file.txt