ChrisInCambo Asked: 2009-09-19 00:33:28 +0800 CST2009-09-19 00:33:28 +0800 CST 2009-09-19 00:33:28 +0800 CST Read the first line of a file using bash 772 Does anyone know of a simple one liner to read the first line of a file in bash? bash 5 Answers Voted Best Answer Etienne Dechamps 2009-09-19T01:56:12+08:002009-09-19T01:56:12+08:00 read -r FIRSTLINE < filename Same result as the other answers but faster because it doesn't spawn any process, as "read" is a built-in bash command. drAlberT 2009-09-19T00:39:55+08:002009-09-19T00:39:55+08:00 head -1 simply Terje Mikal 2009-09-19T00:46:22+08:002009-09-19T00:46:22+08:00 FIRSTLINE=`head -n 1 filename` Stores the line in a variable for later use (note the inverted apostrophes). brandstaetter 2009-09-19T00:36:40+08:002009-09-19T00:36:40+08:00 head -n 1 should do the trick David Poblador i Garcia 2009-09-19T01:20:55+08:002009-09-19T01:20:55+08:00 awk 'NR == 1' /etc/passwd
Same result as the other answers but faster because it doesn't spawn any process, as "read" is a built-in bash command.
simply
Stores the line in a variable for later use (note the inverted apostrophes).
head -n 1
should do the trick