This question already has an answer here:

When I execute

echo `man ls` > tem.txt

I get unformatted output in the text file, I mean output without any new lines, just continues sentences. How do I get formatted output ?
For example, unformatted output looks like:

LS(1) User Commands LS(1) NAME ls - list directory contents SYNOPSIS ls
[OPTION]... [FILE]... DESCRIPTION List information about the FILEs (the
current directory by default). Sort entries alphabetically if none of -
cftuvSUX nor --sort is speci‐ fied. Mandatory arguments to long options are
mandatory for short options too. -a.................

marked as duplicate by Gilles command-line Dec 25 '14 at 14:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Why not do redirect man's output directly? Also, even if you use echo, why haven't you quoted it? – muru Dec 25 '14 at 12:51
  • how do you redirect directly ? – Edward Torvalds Dec 25 '14 at 12:52
  • 2
    man ls > tem.txt – muru Dec 25 '14 at 12:53

You don't need to force man's output via process substitution. Redirection works fine for it:

man ls > tem.txt

Even if you so use process substitution, remember to use quotes, otherwise the output will undergo splitting + globbing from the shell:

echo "$(man ls)" > tem.txt
  • how does double quotes help ? – Edward Torvalds Dec 25 '14 at 12:59
  • globbing is performed on wildcards and commands right ? how on output ? – Edward Torvalds Dec 25 '14 at 13:00
  • 3
    @edwardtorvalds A command line is processed in several stages. Command substitution takes place before the globbing stage. So if the command's output contains wildcards, it will be expanded. Quoting works normally: prevents the shell from expanding wildcards and compressing and replacing all whitespace with spaces. – muru Dec 25 '14 at 13:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.