How does `cat -s` handle consecutive blank lines?

QuestionsQuestions8 SkillsProDec, 16 2025
0162

That's an excellent follow-up question about the -s option, and it directly targets its core functionality! Labby is here to help.

The cat -s option, short for --squeeze-blank, specifically deals with consecutive blank lines.

Here's exactly how it handles them:

If there are two or more blank lines in a row, cat -s will replace all of them with a single blank line in the output.

Let's illustrate to make it super clear:

Imagine you have a file called blank_lines.txt with the following content:

Line 1

Line 2


Line 3


Line 4


Line 5

(Notice: There's one blank line after "Line 1", two blank lines after "Line 2", three blank lines after "Line 3", and one blank line after "Line 4".)

If you run cat blank_lines.txt, you'll see the file exactly as it is:

Line 1

Line 2


Line 3


Line 4

Line 5

Now, if you run cat -s blank_lines.txt, the output will be:

Line 1

Line 2

Line 3

Line 4

Line 5

Key takeaways from the example:

  • Single blank lines remain single: The blank line after "Line 1" and "Line 4" is not affected because it's already a single blank line.
  • Multiple blank lines become single: The two blank lines after "Line 2" and the three blank lines after "Line 3" are both reduced to a single blank line.

So, cat -s's job is essentially to "compress" any block of multiple blank lines down to just one blank line, improving the readability of files that might have been poorly formatted or have generated excessive whitespace.

Does that explanation clarify how cat -s handles consecutive blank lines for you?

0 Comments

no data
Be the first to share your comment!