You can't get that with tr
by itself. tr
is very handy, but is strictly a char-by-char filter, no look-ahead or look-behind.
You might be able to get your example output with sed
, but it would really be painful (I think!). edit (sed master @Sorpigal proves me wrong!)
Here's a solution with awk
/home/shellter:>cat <<-EOS \
| awk 'BEGIN{RS="\n\n"}; { gsub("\n", "", $0) ;printf("%s %s", $0, "\n\n") }'
The answer t
o your question
A conclusive a
nswer isn’t al
ways possible.
When in doubt, ask pe
ople to cite their so
urces, or to explain
Even if we don’t agre
e with you, or tell y
ou.
EOS
# output
The answer to your question
A conclusive answer isnt always possible.
When in doubt, ask people to cite their sources, or to explain
Even if we dont agree with you, or tell you.
Weird, it is displaying as triple-spaced, but it is really dbl-spaced.
Awk has predefined variables that it populates for each file, and each line of text that it reads, i.e.
RS = RecordSeperator -- normally a line of data, but a configurable value, that when set
to '\n\n' means a blank line, or a typical separation on a paragraph
$0 = complete line of text (as defined by the internal variables RS (RecordSeparator)
In this problem, it is each paragraph of data, viewed though
as a record.
$1 = first field in text (as defined by the internal variables FS (FieldSeparator)
which defaults to (possibly multiple) space chars OR tab char
a line with 2 connected spaces chars and 1 tab char has 3 fields)
NF = Number(of)Fields in current line of data (again fields defined by value of FS as
described above)
(there are many others, besides, $0, $n, $NF, $FS, $RS).
you can programatically increment for values like $1, $2, $3, by using a variable as in the example code, like $i (i is a variable that has a number between 2 and NF. The leading '$'
says give me the value of field i (i.e. $2, $3, $4 ...)
I hope this helps.