Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Przetworzenie pliku tekstowego przed jego edycją w Libreoffice

33 views
Skip to first unread message

zakend

unread,
Mar 18, 2013, 5:12:07 PM3/18/13
to
Mam dość duży plik tekstowy. Każda linia stanowi odrębny akapit w libreoffice.
Jak napisac skrypt który:

algorytm
1. wstawi nową linię po [.\n] na końcu linii
2. wstawi nowa linię po ?\n na końcu linii
3. zamieni [,\n] na końcu linii na [,[spacja]]
4. zmieni [-\n] na końcu linii na [spacja] jeżeli przed [-] nie ma spacji
5. zmien [\n] na [spacja] jeżeli po [\n] nie występuje kolejne [\n].

W sumie chodzi o to by otrzymać logiczne akapity przed edycją w Libreoffice.

Z góry dziękuje za sygestię lub rozwiązanie.

Zdzisław A. Kaleta

zakend

unread,
Mar 18, 2013, 5:21:32 PM3/18/13
to
Sorry I translate the previous text

O have rather big text file. Any line is single paragraph in Libreoffice.

How to create script which:

1. will input new line after [.\n] on the end of line,
2. will input new line after [?\n] on the end of line,
3. will change [,\n] for [space] on the end of line,
4. will change [-\n] for [space] on the end of line if there is no [space] before [-]
5. will change [\n] for [space] on the end of line if there is no next [\n] after [\n]

The general idea is to obtain normal paragraphs before edition in Libreoffice.

Thanks in advance for help

Zdzisław A. Kaleta

Ed Morton

unread,
Mar 18, 2013, 5:27:53 PM3/18/13
to
> Zdzis�aw A. Kaleta
>

Post some small, representative sample input and expected output.

Ed.

zakend

unread,
Mar 18, 2013, 5:48:00 PM3/18/13
to
OK. Attache two files one text before and second after.
The meaning of the text is not important only form ;-)

Text before:

"If a virulent virus or even the Rapture depopulated Earth overnight, how long before all trace of humankind vanished? That's the
provocative, and occasionally puckish, question posed by Weisman (An Echo in My Blood) in this imaginative hybrid of solid.
Science reporting and morbid speculation. Days after our disappearance, pumps keeping Manhattan's subways dry would fail,
tunnels would flood, soil under streets would sluice away and the foundations of towering skyscrapers built to last for centuries would start to crumble?
At the other end of the chronological spectrum, anything made of bronze might survive in recognizable form for millions
of years along with one billion pounds of degraded but almost indestructible plastics manufactured since the mid-20th century.
Meanwhile, land freed from mankind's environmentally poisonous footprint would quickly reconstitute itself, as in Chernobyl,
where animal life has returned after 1986's deadly radiation leak, and in the demilitarized zone between North and South Korea,
a refuge since 1953 for the almost-extinct goral mountain goat and Amur leopard.
From a patch of primeval forest in Poland to monumental underground villages in Turkey, Weisman's enthralling tour
of the world of tomorrow explores what little will remain of ancient times while anticipating, often poetically,
what a planet without us would be like."

Text after editing:

"If a virulent virus or even the Rapture depopulated Earth overnight, how long before all trace of humankind vanished? That's the provocative, and occasionally puckish, question posed by Weisman (An Echo in My Blood) in this imaginative hybrid of solid.

Science reporting and morbid speculation. Days after our disappearance, pumps keeping Manhattan's subways dry would fail, tunnels would flood, soil under streets would sluice away and the foundations of towering skyscrapers built to last for centuries would start to crumble?

At the other end of the chronological spectrum, anything made of bronze might survive in recognizable form for millions of years along with one billion pounds of degraded but almost indestructible plastics manufactured since the mid-20th century.

Meanwhile, land freed from mankind's environmentally poisonous footprint would quickly reconstitute itself, as in Chernobyl, where animal life has returned after 1986's deadly radiation leak, and in the demilitarized zone between North and South Korea, a refuge since 1953 for the almost-extinct goral mountain goat and Amur leopard.

From a patch of primeval forest in Poland to monumental underground villages in Turkey, Weisman's enthralling tour of the world of tomorrow explores what little will remain of ancient times while anticipating, often poetically, what a planet without us would be like."

ZAK

Bernd Nawothnig

unread,
Mar 19, 2013, 6:00:31 AM3/19/13
to
On 2013-03-18, zakend wrote:
> Text after editing:
> [...]

#v+
#!/usr/bin/awk -f

{ l = l != "" ? l" "$0 : $0 }
/^.*[.?!]$/ { print l"\n"; l = "" }
END { print l }
#v-

I added '!' to the list of EOL-symbols.




Bernd

--
no time toulouse

Luuk

unread,
Mar 20, 2013, 2:17:01 PM3/20/13
to
> Zdzis�aw A. Kaleta
>


You can also read the file into LibreOffice,
and than use Format/Paragraph, and then change
"Spacing below paragraph"


zakend

unread,
Mar 20, 2013, 4:59:57 PM3/20/13
to Bernd.N...@web.de
Wonderful. Work like charm. Thank You.

Now I try to understood the script ;-) such the life of greenhorns.

I more question. If it is possible to force the script start form lets say 40th line?

zak

Luuk

unread,
Mar 20, 2013, 5:43:14 PM3/20/13
to
On 20-03-2013 21:59, zakend wrote:
> W dniu wtorek, 19 marca 2013 11:00:31 UTC+1 u�ytkownik Bernd Nawothnig napisa�:
>> On 2013-03-18, zakend wrote:
>>
>>> Text after editing:
>>
>>> [...]
>>
>>
>>
>> #v+
>>
>> #!/usr/bin/awk -f
>>
>>
>>
>> { l = l != "" ? l" "$0 : $0 }
>>
>> /^.*[.?!]$/ { print l"\n"; l = "" }
>>
>> END { print l }
>>
>> #v-
>>
>>
>>
>> I added '!' to the list of EOL-symbols.
>>
>
> Wonderful. Work like charm. Thank You.
>
> Now I try to understood the script ;-) such the life of greenhorns.
>
> I more question. If it is possible to force the script start form
lets say 40th line?
>
> zak

from tha man-pages:
FNR The input record number in the current input file.

so you should add a check for FNR, something like:

FNR>=40 { l = l != "" ? l" "$0 : $0 }

zakend

unread,
Mar 20, 2013, 7:21:26 PM3/20/13
to
W dniu środa, 20 marca 2013 22:43:14 UTC+1 użytkownik Luuk napisał:
> On 20-03-2013 21:59, zakend wrote:
>
> > W dniu wtorek, 19 marca 2013 11:00:31 UTC+1 u?ytkownik Bernd Nawothnig napisa?:
>
> >> On 2013-03-18, zakend wrote:
>
> >>
>
> >>> Text after editing:
>
> >>
>
> >>> [...]
>
> >>
>
> >>
>
> >>
>
> >> #v+
>
> >>
>
> >> #!/usr/bin/awk -f
>
> >>
>
> >>
>
> >>
>
> >> { l = l != "" ? l" "$0 : $0 }
>
> >>
>
> >> /^.*[.?!]$/ { print l"\n"; l = "" }
>
> >>
>
> >> END { print l }
>
> >>
>
> >> #v-
>
> >>
>
> >>
>
> >>
>
> >> I added '!' to the list of EOL-symbols.
>
> >>
>
> >
>
> > Wonderful. Work like charm. Thank You.
>
> >
>
> > Now I try to understood the script ;-) such the life of greenhorns.
>
> >
>
> > I more question. If it is possible to force the script start form
>
> lets say 40th line?
>
> >
>
> > zak
>
>
>
> from tha man-pages:
>
> FNR The input record number in the current input file.
>
>
>
> so you should add a check for FNR, something like:
>
>
>
> FNR>=40 { l = l != "" ? l" "$0 : $0 }
>
> /^.*[.?!]$/ { print l"\n"; l = "" }
>
> END { print l }

OK and if I want the first 40 line in file put to output without change?

zak

zakend

unread,
Mar 20, 2013, 7:26:08 PM3/20/13
to
W dniu środa, 20 marca 2013 22:43:14 UTC+1 użytkownik Luuk napisał:
> On 20-03-2013 21:59, zakend wrote:
>
> > W dniu wtorek, 19 marca 2013 11:00:31 UTC+1 u?ytkownik Bernd Nawothnig napisa?:
>
> >> On 2013-03-18, zakend wrote:
>
> >>
>
> >>> Text after editing:
>
> >>
>
> >>> [...]
>
> >>
>
> >>
>
> >>
>
> >> #v+
>
> >>
>
> >> #!/usr/bin/awk -f
>
> >>
>
> >>
>
> >>
>
> >> { l = l != "" ? l" "$0 : $0 }
>
> >>
>
> >> /^.*[.?!]$/ { print l"\n"; l = "" }
>
> >>
>
> >> END { print l }
>
> >>
>
> >> #v-
>
> >>
>
> >>
>
> >>
>
> >> I added '!' to the list of EOL-symbols.
>
> >>
>
> >
>
> > Wonderful. Work like charm. Thank You.
>
> >
>
> > Now I try to understood the script ;-) such the life of greenhorns.
>
> >
>
> > I more question. If it is possible to force the script start form
>
> lets say 40th line?
>
> >
>
> > zak
>
>
>
> from tha man-pages:
>
> FNR The input record number in the current input file.
>
>
>
> so you should add a check for FNR, something like:
>
>
>
> FNR>=40 { l = l != "" ? l" "$0 : $0 }
>
> /^.*[.?!]$/ { print l"\n"; l = "" }
>
> END { print l }

And one more question. What mean #v+ before #!/usr/bin/awk -f? I have thought that #!/usr/bin/awk -f has to be first line of the script.

zakend

unread,
Mar 21, 2013, 4:45:28 AM3/21/13
to
Sorry, I didn't think before asking. The answer is obvious even to greenhorn.

The script will look this:

#!/usr/bin/awk -f
#rom https://groups.google.com/forum/?hl=pl&fromgroups=#!topic/comp.lang.awk/1SiyHFrILLU
#v+ # I don't know

FNR<=40 { print } # FNR lines without changed them
FNR>=41 { l = l != "" ? l" "$0 : $0 } # FNR lines wchich will change
/^.*[.?!]$/ { print l"\n"; l = "" } # transformation of text
END { print l } # printing output efect of changed lines

#v- # I don't know

And of course calling it as:

my-account$ script.awk original-file >> output-file

zak

Bernd Nawothnig

unread,
Mar 21, 2013, 5:42:34 PM3/21/13
to
On 2013-03-20, zakend wrote:

> And one more question. What mean #v+ before #!/usr/bin/awk -f?

Thats just for highlighting a piece of code in my reader.

Simply copy the lines between #v+ and #v-, not including them.

> I have thought that #!/usr/bin/awk -f has to be first line of the
> script.

And that is true - as long as /usr/bin/awk is the location of your awk
binary.



Bernd

--
Die Antisemiten vergeben es den Juden nicht, dass die Juden Geist
haben - und Geld: der Antisemitismus, ein Name der
Schlechtweggekommenen. [Friedrich Nietzsche]

Bernd Nawothnig

unread,
Mar 21, 2013, 5:45:34 PM3/21/13
to
On 2013-03-20, zakend wrote:

>> FNR>=40 { l = l != "" ? l" "$0 : $0 }
>>
>> /^.*[.?!]$/ { print l"\n"; l = "" }
>>
>> END { print l }
>
> OK and if I want the first 40 line in file put to output without change?

Very simple:

FNR<40 { print }
FNR>=40 { l = l != "" ? l" "$0 : $0 }
/^.*[.?!]$/ { print l"\n"; l = "" }
END { print l }




0 new messages