Bash shell

Output Nth Line of File in Bash

A memo on how to output the Nth line of a file in Bash on Linux command line. Uses the sed command. Can be used for things like looping through with for and outputting one line at a time.

Shou Arisaka
1 min read
Oct 30, 2025

A memo on how to output the Nth line of a file in Bash on Linux command line. Uses the sed command.

Can be used for things like looping through with for and outputting one line at a time.

# Line 1
sed "1q;d" names.txt
# Line 2
sed "2q;d" names.txt
# Line 3
sed "3q;d" names.txt

Share this article

Shou Arisaka Oct 30, 2025

๐Ÿ”— Copy Links