1

Explanation

With the help of REGEX I am trying to convert italian synonym database to the following format:

synonym1|synonym2|synonym3
anothersynonym1|anothersynonym2
...........
......

At this moment I have unconverted synonyms database in this format:

a|       - word
|per     -it's synonym
|verso   -another synonym of the word "a" in the second row
abate|    - second word
|priore|superiore
abbacchiare|
|avvilire|deprimere
abbacchiarsi|
|abbattersi|abbiosciarsi|accasciarsi

Clarification: I would like to use Regular Expression to match all lines beginning with "|" (pipeline) and move them to the line above to merge with the word matching with lines ending with (Pipeline) and also moving in rows beginning with "|" (second - third - fourth lines of synonyms which may be merged together, obviously when merged lines with "ending and beginning" Pipelines one of the (Pipelines) should removed to get desired format:

Example of the converted database from unconverted database above

a|per|verso
abate|priore|superiore
abbachiare|avvilire|deprimere
abbachiarsi|abbattersi|abbiosciarsi|accasciarsi

Can anybody help me to find exact REGULAR EXPRESSION by using function FIND and REPLACE with any text editor?

2 Answers 2

0

If you are using Windows you can use the Extended Search Mode of Notepad++ to do this in 2 steps:

1: Replace |\r\n| with | - This will find all of the first synonyms

first replace

a|per
|verso
abate|priore|superiore
abbacchiare|avvilire|deprimere
abbacchiarsi|abbattersi|abbiosciarsi|accasciarsi

2: Replace \r\n| with | - This will find all of the subsequent synonyms

second replace

a|per|verso
abate|priore|superiore
abbacchiare|avvilire|deprimere
abbacchiarsi|abbattersi|abbiosciarsi|accasciarsi
1
  • Thank you very , very much , very descriptive even with screenshots , your solution worked perfectly exactly how you wrote !!! Oct 19, 2011 at 13:04
0
perl -ne 'chomp; print /^(.*)\|\s*$/?"\n$1":$_' filename

a|per|verso
abate|priore|superiore
abbacchiare|avvilire|deprimere
abbacchiarsi|abbattersi|abbiosciarsi|accasciarsi

Or, if you are fussy about leading and trailing newlines:

perl -ne 'chomp; print /^(.*)\|\s*$/?$.==1?$1:"\n$1":$_;END{print"\n"}' filename
a|per|verso
abate|priore|superiore
abbacchiare|avvilire|deprimere
abbacchiarsi|abbattersi|abbiosciarsi|accasciarsi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .