Tenth Line - Problem
Given a text file file.txt, write a shell command or script to print just the 10th line of the file.
Note: If the file has fewer than 10 lines, the output should be empty (nothing printed).
Input & Output
Example 1 — File with 15 lines
$
Input:
file.txt contains 15 lines, line 10 is "tenth line content"
›
Output:
tenth line content
💡 Note:
The file has more than 10 lines, so we successfully extract and print the 10th line
Example 2 — File with exactly 10 lines
$
Input:
file.txt contains exactly 10 lines, line 10 is "last line"
›
Output:
last line
💡 Note:
The file has exactly 10 lines, so line 10 exists and is printed
Example 3 — File with fewer than 10 lines
$
Input:
file.txt contains only 5 lines
›
Output:
💡 Note:
The file has fewer than 10 lines, so there's no 10th line to print (empty output)
Constraints
- The file may contain 0 to any number of lines
- Each line can be up to 1000 characters
- If file doesn't exist or has fewer than 10 lines, output should be empty
Visualization
Tap to expand
Understanding the Visualization
1
Input File
Text file with multiple lines, need line 10
2
Process
Use shell commands to locate 10th line
3
Output
Print only the 10th line content
Key Takeaway
🎯 Key Insight: Use Unix line addressing tools to directly access specific line numbers without reading/storing entire file content
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code