π§ What does this Linux command do?
sed -n 'BEGIN,ENDp' /path/to/file.txt
At first glance, it looks simple. But this small command can save a lot of time when working with logs and large text files.
Let’s break it down:
-
sed
β a stream editor for processing text;
-
-n
β disables automatic output of every line;
-
BEGIN,END
β defines the range of lines to process;
-
p
β prints only the selected lines.
Example:
sed -n '100,150p' application.log
This will print only lines from 100 to 150 of the log file.
You can also use text patterns:
sed -n '/ERROR BEGIN/,/ERROR END/p' application.log
This extracts everything between two markers:
ERROR BEGIN
...
ERROR END
A very useful technique when you need to quickly inspect a specific part of a huge log file without opening it in an editor.
For example:
- debugging production issues;
- analyzing application errors;
- investigating server logs;
- checking deployment output.
Small Linux commands are often the tools that make engineers faster.
Do you use
sed
in your daily workflow? π¨βπ»
π₯ Watch the video tutorial on YouTube
If you’d like to see these sed examples demonstrated
on a real Linux system, watch my full YouTube tutorial.
Subscribe to my Linux Tutorials YouTube channel.