Issue
I have this text:
Be sure to see if the code requires firestops in
the stud walls.* These are wood strips between
the studs that will prevent flames and hot air
from moving upward within the wall. (Some
areas require that firestopping be placed no more
than one story apart. In platform-frame con-
struction, the floor platform acts as an adequate
divider and no firestopping is required.) Fire-
stopping will be required in most cases between
the joists at the places where they are supported.
These solid wooden bridges prevent the hori-
zontal movement of fire and hot gases within the
floor.
The 1970’s provided a critical turning point for
energy consumption in this country and for
other major energy-consuming countries. With
the Arab oil embargo, prices rose at an outra-
geous rate, creating a scarcity of gasoline and
heating oil. While it is still debated whether the
crisis was legitimate or created to inflate crude-
oil prices, there were lessons to be learned from
the fuel shortage. First, fuel oil is a limited and
irreplaceable resource. Second, the Western
world is burning oil at an unprecedented and
wasteful rate. The remedy is to conserve fuel as
much as possible and to explore and discover
new, regenerative sources of energy such as
solar power.
I would like to make a paragraph be on a single line instead of multiple lines. So the output will be this:
Be sure to see if the code requires firestops in the stud walls.* These are wood strips between the studs that will prevent flames and hot air from moving upward within the wall. (Some areas require that firestopping be placed no more than one story apart. In platform-frame con- struction, the floor platform acts as an adequate divider and no firestopping is required.) Fire- stopping will be required in most cases between the joists at the places where they are supported. These solid wooden bridges prevent the hori-zontal movement of fire and hot gases within the floor.
The 1970’s provided a critical turning point for energy consumption in this country and for other major energy-consuming countries. With the Arab oil embargo, prices rose at an outra-geous rate, creating a scarcity of gasoline and heating oil. While it is still debated whether the crisis was legitimate or created to inflate crude-oil prices, there were lessons to be learned from the fuel shortage. First, fuel oil is a limited and irreplaceable resource. Second, the Western world is burning oil at an unprecedented and wasteful rate. The remedy is to conserve fuel as much as possible and to explore and discover new, regenerative sources of energy such as solar power.
I'm seeing there's thing like sed and awk, but I'm not too sure how either one works, so far they seem alien to me.
Thank you for reading and helping if you can.
So far I only do this manually, but I honestly do not know how to make this work as I haven't found yet a solution for similar problem.
Solution
In addition to simply joining the lines in each paragraph, you need to handle trailing hyphens '-'
and ensure no space is appended following the hyphen. You can do that by simply building each line, appending the contents of each line using a ternary to check whether the last
character in the preceding line was '-'
.
A short implementation would be:
awk '
NF==0 { print str "\n"; str="" }
{ str=str (str && last!="-" ? " " : "") $0 }
{ last=substr($0,length($0),1) }
END { print str }
' file
Example Output
With your example contents in file
the result is:
Be sure to see if the code requires firestops in the stud walls.* These are wood strips between the studs that will prevent flames and hot air from moving upward within the wall. (Some areas require that firestopping be placed no more than one story apart. In platform-frame con-struction, the floor platform acts as an adequate divider and no firestopping is required.) Fire-stopping will be required in most cases between the joists at the places where they are supported. These solid wooden bridges prevent the hori-zontal movement of fire and hot gases within the floor.
The 1970’s provided a critical turning point for energy consumption in this country and for other major energy-consuming countries. With the Arab oil embargo, prices rose at an outra-geous rate, creating a scarcity of gasoline and heating oil. While it is still debated whether the crisis was legitimate or created to inflate crude-oil prices, there were lessons to be learned from the fuel shortage. First, fuel oil is a limited and irreplaceable resource. Second, the Western world is burning oil at an unprecedented and wasteful rate. The remedy is to conserve fuel as much as possible and to explore and discover new, regenerative sources of energy such as solar power.
NOTE: without a dictionary lookup, there is no way to distinguish between "hori-zontal"
which should have the hyphen removed and, e.g. "crude-oil"
which is properly hyphenated when the hyphen appears at the end of the line.
Answered By - David C. Rankin Answer Checked By - Cary Denson (WPSolving Admin)