[clue-tech] Parsing text editor wanted

Lynn Danielson lynnd at techangle.com
Sat Jul 29 01:51:40 MDT 2000


Kevin Cullis wrote:
> 
> I'd like to parse text which has been cut and pasted from the Net into a
> text file to be uploaded into a spreadsheet/database. While vi works,
> the problem is multiple spaces to be deleted between the fields of text
> to be imported.  The basic issue is a find and replace with a replace
> all to remove the multiple spaces.

One possible solution is to use tr and sed.  If you've pasted your
text into a file you can then cat that file through tr and sed and
redirect the output to another file.  For example, if you've saved
your captured text in file1 and would like all of the spaces between
words taken out and replaced with commas, you could do the following:

  cat file1 | tr -s " " | sed -e 's/ /,/g' > file2

The tr squeezes out the extra "space" characters, then sed 
substitutes commas for the remaining spaces.  A simpler way to
see how this works is to use it on a long directory listing:

  ls -l | tr -s " " | sed -e 's/ /,/g'


This will only give you your desired result if you want every 
word delimited by commas instead of spaces.  I'm sure a more 
comprehensive and elegant solution is available using perl or 
python and regular expressions.  Let me know if this works for 
you.

Lynn



More information about the clue-tech mailing list