nerdexam
Linux_Foundation

LFCS · Question #812

Which of the following commands will reduce all consecutive spaces down to a single space?

The correct answer is E. tr -s ' ' < a.txt > b.txt. The tr command with the -s (squeeze) option is used to replace sequences of identical characters with a single occurrence of that character.

Submitted by hans_de· Apr 18, 2026Essential Commands

Question

Which of the following commands will reduce all consecutive spaces down to a single space?

Options

  • Atr '\s' ' ' < a.txt > b.txt
  • Btr -c ' ' < a.txt > b.txt
  • Ctr -d ' ' < a.txt > b.txt
  • Dtr -r ' ' '\n' < a.txt > b.txt
  • Etr -s ' ' < a.txt > b.txt

How the community answered

(28 responses)
  • A
    4% (1)
  • D
    4% (1)
  • E
    93% (26)

Why each option

The `tr` command with the `-s` (squeeze) option is used to replace sequences of identical characters with a single occurrence of that character.

Atr '\s' ' ' < a.txt > b.txt

The `tr` command with `\s` might not be universally interpreted as a whitespace character, and it does not perform squeezing of consecutive characters.

Btr -c ' ' < a.txt > b.txt

The `tr -c ' '` command complements the set of characters, meaning it operates on characters *not* in the specified set, which is not for reducing consecutive spaces.

Ctr -d ' ' < a.txt > b.txt

The `tr -d ' '` command deletes all occurrences of the specified character, which would remove all spaces rather than reducing consecutive ones.

Dtr -r ' ' '\n' < a.txt > b.txt

The `-r` option is not a standard or recognized option for the `tr` command, making this command syntactically incorrect for the intended purpose.

Etr -s ' ' < a.txt > b.txtCorrect

The `tr -s ' '` command uses the `-s` or `--squeeze-repeats` option to replace each sequence of two or more identical characters specified in SET1 with a single instance of that character. Therefore, it will reduce all consecutive spaces down to a single space.

Concept tested: `tr` command character squeezing

Source: https://man7.org/linux/man-pages/man1/tr.1.html

Topics

#tr command#text processing#command line utilities

Community Discussion

No community discussion yet for this question.

Full LFCS Practice