2

I have an .rtf , ~70 pages dictionary manuscript at hand in the following format:

enter image description here

I have been asked to change those lines to:

enter image description here

without formatting it is an easy thing to do, but i couldn't figure out how to do that in the desired formatting.

I tried libreoffice's search & replace tool with regular expressions to first put the first braces in bold for all entries. And then i tried this for closing braces:

Find: \[([:alpha:]{1:20})

Replace:&]

it works fine but it makes like this:

enter image description here

i.e. it copies the format of the previous(first character selected by search command) part and applies to the whole thing i choose to replace.

I also tried using sed for substitution but apparently it doesn't work with formatted .rtf files when using basic syntax. It opens the .rtf as a plain text, so all the codes for formatting and file info appears as a text, therefore my:

sed "s/ / [/1" dictionary.rtf > dictionary1.rtf and its counterpart for closing braces won't work, because it also tries to change the spaces with space+open brace appearances in the formatting codes.


So, to sum up, i have an .rtf file in the desired formatting, and on the other hand, i have a plain text with pronunciation part enclosed by braces, produced by sed output from the plain text version of dictionary.

I am wondering if there is a way to convert an .rtf file which contains only the plain text inside, to the format i described above.

Any help would appreciated, as long as it does the desired job. If you can fix my libreoffice search & replace, that would also do it.

Thank you!

  • Try sed -r 's/^([^[:blank:]]+)[[:blank:]]+([^[:blank:]]+)[[:blank:]]+(.*)/\1 [ \2 ] \3/' file.rtf – heemayl Aug 28 '16 at 0:56
  • @heemayl no, that didn't change the file at all :( – etka Aug 28 '16 at 1:04
  • Please edit your question and add some actual chuck and your desired output from that. The chuck you have provided working fine with the sed one for me. – heemayl Aug 28 '16 at 1:07
  • @heemayl yeah, sorry i didn't think that someone will give a straight to the point answer like that. Done editing. – etka Aug 28 '16 at 1:20
  • RTF is just plain text file with many control sequences in it. You already have control sequences in right places (because the text changes colors in exactly right places where you want to place other stuff). You may use these control sequences as markup. With sed, you add "[" before to-violet markup. Before the to-black markup, you have to add the to-orange markup and "]". This is slightly complicated by the fact that the rtf sequences are very complicated and use characters that need to be escaped in sed. – ludvik02 Sep 11 '16 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.