我有這段文字:
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.
我想讓一個段落在一行而不是多行。所以輸出將是這樣的:
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.
我看到有 sed 和 awk 之類的東西,但我不太確定其中任何一個是如何作業的,到目前為止它們對我來說似乎很陌生。
如果可以的話,感謝您的閱讀和幫助。
到目前為止,我只手動執行此操作,但老實說,我不知道如何完成這項作業,因為我還沒有找到類似問題的解決方案。
uj5u.com熱心網友回復:
嘗試類似:
export UNUSED_CHAR="@" # Pick a delimiting character that doesn't exist in the text
tr "\n" "${UNUSED_CHAR}" < filename `# replace all newlines with the delimiter` \
| sed "s/${UNUSED_CHAR}${UNUSED_CHAR}/\n\n/g" `# replace consecutive delimiters with 2 newlines` \
| sed "s/${UNUSED_CHAR}-//g" `# combine hyphentated words` \
| sed "s/${UNUSED_CHAR}/ /g" `# replace remaining instances of delimiter with a single space` \
> new_filename # Write results to a new file
uj5u.com熱心網友回復:
使用 GNUsed
$ sed -E ':a;N;s/\n([[:alpha:]])/ \1/;ba' input_file
e 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.
對于預期的輸出,您也可以嘗試
$ sed -E '/^$/s/^/###/' | sed -Ez ':a;s/\n/ /;ta;s/# /\n\n/;s/$/\n/' input_file
e 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.
uj5u.com熱心網友回復:
簡單的awk
解決方案
此解決方案通過將awk
record
分隔符 ( RS
) 設定為空字串來作業(這會導致在由空白(或僅空白行)分隔的記錄中讀取檔案。
(假設您的文本在檔案 paras.txt 中)
awk 'BEGIN{RS="";} //{print "\n"} {$1=$1;printf $0}' paragraphs.txt
record
分隔符設定在塊BEGIN
中。//
如果遇到空行,該塊告訴 awk 列印一個新行(因為我們需要分隔你的段落)。主塊使用將任何欄位設定為自身的技巧,以使 awk 用它看到的內容(即忽略換行符)重新調整整個記錄($0)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/528967.html
標籤:重击