Version 0 of Text processing tips

Updated 2005-03-09 07:58:53 by AM

Arjen Markus (9 March 2005) I created this page to collect small code fragments about the various tricks you can use to process text. Most of the time these tricks do not merit a page of their own, but they do merit a place on the Wiki :).


AM I had a problem with files that contain "continued lines". Here is a sketch:

    line with info \
          continued on the next line (see the backslash) \
          and the info is: Aha=BBBB
    another line with info - here the info is: Aha=CC

I needed to extract information from the complete lines. Now usually I read files line by line and analyse the lines one by one. You can not do that with this type of layout. Or can you? Here is my little trick:

   set contents [read $infile] 
   set contents [string map [list "\\\n" " "] $contents]
   foreach line [split $contents \n] {
      .. process the line ...
   }

This little fragment of code=:

  • reads the complete file (in my case they were not very large)
  • replaces the trailing backslash (and the newline) by a single space
  • splits the contents into separate lines again

No need to check if the line is complete or not - just use a few commands.


... next trick? ...


[ Category Word and Text processing ]