HackerRank - Head of a Text File #1
April - 25/2025
Problem:
In this challenge, we practice using the head command to display the first n lines of a text file. Display
the first 20 lines of an input file.
# Input
- From fairest creatures we desire increase,
- That thereby beauty's rose might never die,
- But as the riper should by time decease,
- His tender heir might bear his memory:
- But thou contracted to thine own bright eyes,
# Output
- From fairest creatures we desire increase,
- That thereby beauty's rose might never die,
- But as the riper should by time decease,
- His tender heir might bear his memory:
- But thou contracted to thine own bright eyes,
# Solution
head -n 20
# Solution_01
while read line
do
echo "$line";
done | head -n 20
Post: