How do I get the first line in Linux?

Julipkq

New member
How do I get the first line in Linux?
Answer
To store the line itself, use the
var=$(command)
syntax. In this case, line=$(awk ‘NR==1 {print; exit}’ file) . With the equivalent line=$(sed -n ‘1p’ file) . will be marginally faster as read is a built-in bash command.
 

Tìm kiếm

Back
Top