The sed -n option suppresses the default output of sed, which means that it will not print every line of the input file to the standard output. Instead, it allows you to control what gets printed by using specific commands.
Here's how it works:
-
Suppress Output: By using
-n,sedwill not automatically print each line after processing it. -
Explicit Printing: You can use the
pcommand to explicitly tellsedwhich lines to print. For example:sed -n '1,5p' filename.txtThis command will print only lines 1 to 5 of
filename.txt. -
Combining with Other Commands: You can combine
-nwith other commands to filter and print specific lines based on patterns. For example:sed -n '/pattern/p' filename.txtThis will print only the lines that match "pattern".
Using -n is useful when you want to avoid cluttering the output with lines that you do not need to see.
