olivier has asked for the wisdom of the Perl Monks concerning the following question:
I have a whole list of text files with text in German, French and English. All lines containing meaningful text are preceded by 4 spaces. However, I would like to have only a single line of text under each language for those language lines that space multiple lines (a line being 76 characters long maximum at present). In other words, the above would become:line de Bitte lesen Sie die Gebrauchsanweisung gut durch und bewahren Sie diese auf. en Please read these instructions carefully and keep for future reference. fr Lire et conserver ces instructions pour toute utilisation future du produit. line de 19 Zubehoerteile. en 19 Accessories. fr 19 Accessoires line de 10 Aktivitaeten. en 10 Activities. fr 10 Activite's.
The languages text that already span only 1 line are left untouched, whereas the other lines, where the language text spans more than 1 lines, are joined. I have tried several regular expressions, all of them as Perl one liners as I thought it would be an extra challenge to do it all one 1 line, such asline de Bitte lesen Sie die Gebrauchsanweisung gut durch und bewahren Sie +diese auf. en Please read these instructions carefully and keep for future refer +ence. fr Lire et conserver ces instructions pour toute utilisation future d +u produit. line de 19 Zubehoerteile. en 19 Accessories. fr 19 Accessoires line de 10 Aktivitaeten. en 10 Activities. fr 10 Activite's.
However, none of my regular expressions works. It looks as if anything specified after the \n is ignored. Any idea? Any help would be immensely appreciated? Thank you very muchperl -i.bak -pe 's/^\s\s\s\s(.*)$\n\s\s\s\s/$1/g' myfile.txt perl -i.bak -pe 's/\n\s\s\s\s/ /gm' myfile.txt
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: replace \n with space to join indented lines
by ikegami (Patriarch) on Dec 05, 2006 at 06:32 UTC | |
by olivier (Initiate) on Dec 05, 2006 at 13:17 UTC | |
by ikegami (Patriarch) on Dec 05, 2006 at 16:10 UTC | |
|
Re: replace \n with space to join indented lines
by jwkrahn (Abbot) on Dec 05, 2006 at 07:35 UTC | |
by olivier (Initiate) on Dec 05, 2006 at 13:29 UTC | |
by jwkrahn (Abbot) on Dec 05, 2006 at 15:37 UTC | |
by olivier (Initiate) on Dec 06, 2006 at 16:39 UTC | |
|
Re: replace \n with space to join indented lines
by Anonymous Monk on Dec 05, 2006 at 06:21 UTC | |
by olivier (Initiate) on Dec 05, 2006 at 13:15 UTC |