Skip to main content
deleted 312 characters in body
Source Link
Ed Morton
  • 35.9k
  • 6
  • 25
  • 60

If you don't mind other chains of spaces within the lines being converted to blanks along with the newlines:

$ awk -v RS= '{$1=$1}1' file
These are the words for sentence 1
these are the words for sentence 2

or if you want tabs, etc. retained and only newlines converted to blanks:

$ awk -v RS= -F'\n' '{$1=$1}1' file
These are the words for sentence 1
these are the words for sentence 2

If you don't mind other chains of spaces within the lines being converted to blanks along with the newlines:

$ awk -v RS= '{$1=$1}1' file
These are the words for sentence 1
these are the words for sentence 2

or if you want tabs, etc. retained and only newlines converted to blanks:

$ awk -v RS= -F'\n' '{$1=$1}1' file
These are the words for sentence 1
these are the words for sentence 2
$ awk -v RS= '{$1=$1}1' file
These are the words for sentence 1
these are the words for sentence 2
added 243 characters in body
Source Link
Ed Morton
  • 35.9k
  • 6
  • 25
  • 60

If you don't mind other chains of spaces within the lines being converted to blanks along with the newlines:

$ awk -v RS= '{$1=$1}1' file
These are the words for sentence 1
these are the words for sentence 2

or if you want tabs, etc. retained and only newlines converted to blanks:

$ awk -v RS= -F'\n' '{$1=$1}1' file
These are the words for sentence 1
these are the words for sentence 2
$ awk -v RS= -F'\n' '{$1=$1}1' file
These are the words for sentence 1
these are the words for sentence 2

If you don't mind other chains of spaces within the lines being converted to blanks along with the newlines:

$ awk -v RS= '{$1=$1}1' file
These are the words for sentence 1
these are the words for sentence 2

or if you want tabs, etc. retained and only newlines converted to blanks:

$ awk -v RS= -F'\n' '{$1=$1}1' file
These are the words for sentence 1
these are the words for sentence 2
deleted 178 characters in body
Source Link
Ed Morton
  • 35.9k
  • 6
  • 25
  • 60

If you don't really have trailing blanks at the end of some lines of input:

$ awk -v RS= -F'\n' '{$1=$1}1' file
These are the words for sentence 1
these are the words for sentence 2

If you can have trailing blanks on input lines then:

awk -v RS= -F' *\n' '{$1=$1}1' file

If you don't really have trailing blanks at the end of some lines of input:

$ awk -v RS= -F'\n' '{$1=$1}1' file
These are the words for sentence 1
these are the words for sentence 2

If you can have trailing blanks on input lines then:

awk -v RS= -F' *\n' '{$1=$1}1' file
$ awk -v RS= -F'\n' '{$1=$1}1' file
These are the words for sentence 1
these are the words for sentence 2
deleted 6 characters in body
Source Link
Ed Morton
  • 35.9k
  • 6
  • 25
  • 60
Loading
Source Link
Ed Morton
  • 35.9k
  • 6
  • 25
  • 60
Loading