To look at the first few lines of a file, type head filename, where filename is the name of the file you want to look at, and then press <Enter>. By default, head shows you the first 10 lines of a file.
Just echo the first list of your source file into your target file. For which head -n 1 source. txt > target.
The default command which comes to our mind is the head command. head with the option "-1" displays the first line. 2.
You don't need cat
.
head -1 file
will work fine.
You don't, use head
instead.
head -n 1 file.txt
There are many different ways:
sed -n 1p file
head -n 1 file
awk 'NR==1' file
You could use cat file.txt | head -1
, but it would probably be better to use head directly, as in head -1 file.txt
.
This may not be possible with cat
. Is there a reason you have to use cat
?
If you simply need to do it with a bash command, this should work for you:
head -n 1 file.txt
cat
alone may not be possible, but if you don't want to use head
this works:
cat <file> | awk 'NR == 1'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With