удалить недостатки в тексте после преобразования с помощью PDF OCR техники

* означает ноль или более совпадений, и это соответствует как можно скорее. Если вы запустите эту команду без флага g (что означает, что sed остановится после первой замены), вы получите в качестве вывода habc 123 . Это связано с тем, что он начинает чтение слева направо, и поскольку он не может соответствовать a , он просто сопоставляет начало строки и затем останавливается на нем.

Используя глобальный флаг ( g ), он будет продолжать попытки сопоставить остальную часть строки, и поскольку * соответствует пустой строке, когда он не может сопоставить ничего другого , он будет помещать h каждый раз, когда не сможет сопоставить больше чисел.

Обратите внимание, что ваша вторая попытка эквивалентна sed "s / [0-9] \ + / h /" . Здесь + означает одно или несколько совпадений, что означает, что он не будет соответствовать пустой строке, если не найдет номер для замены.

1
05.10.2018, 20:58
2 ответа

Вы можете использовать линейную строку awkдля удаления дополнительных возвратов каретки, что-то вроде этого:

awk '{gsub(/\n/,""); gsub(/\r/,""); print}' RS='' file

biochemistry can be divided in three fields; molecular genetics, protein science and metabolism. Over the last decades of the 20th century, biochemistry has through these three disciplines become successful at explaining living processes. Almost all areas of the life sciences are being uncovered and developed by biochemical methodology and research.[2] Biochemistry focuses on understanding how biological molecules give rise to the processes that occur within living cells and between cells,[3] which in turn relates greatly to the study and understanding of, organs, and organism structure and function[4]
Biochemistry is closely related to molecular biology, the study of the molecular mechanisms by which genetic information encoded in DNA is able to result in the processes of life.[5]
Much of biochemistry deals with the structures,  and interactions of biological macromolecules, such as proteins, nucleic acids, carbohydrates and lipids, which provide the structure of cells and perform many of the functions associated with life.[6] The chemistry of the cell also depends on the  of smaller molecules and ions. These can be inorganic, for example water and metal ions, or organic, for example the amino acids, which are used to synthesize proteins.[7] The mechanisms by which cells harness energy from their environment via chemical reactions are known as metabolism. The findings of biochemistry are applied primarily in medicine, nutrition, and agriculture. In medicine, biochemists investigate the causes and cures of diseases.[8] In nutrition, they study how to maintain health wellness and study the effects of nutritional deficiencies.[9] In agriculture, biochemists investigate soil and fertilizers, and try to discover ways to improve crop cultivation, crop storage and pest control.

gsubфункция имеет следующий вид:

gsub(regexp, replacement [, target])

Это похоже на функцию sub, за исключением того, что gsub заменяет все самые длинные, самые левые, не -неперекрывающиеся совпадающие подстроки, которые она может найти. `g' в gsub означает "глобальный", что означает замену везде

gsub(/\n/,"") replaces all newline occurrences within a string with non for all input text. 

gsub(/\r/,"") replace all carriage return (ASCII code 13) occurrences with non for all input text. 
1
27.01.2020, 23:31

Возможно, есть что улучшить, но вот начало:

perl -0777 -ne 's/([^ ])$\\n/\1/g; s/\\n/ /g; print' < input | fmt

Он использует perl для объединения новых строк --продолжающихся строк, если строка заканчивается пробелом, в противном случае полностью удаляет новые строки, а затем передает вывод через fmtдля разбиения длинных строк.

1
27.01.2020, 23:31

Теги

Похожие вопросы