[CLUE-Tech] Text processing via vi and paste

Kevin Cullis kevincu at orci.com
Sun Mar 18 09:53:49 MST 2001


Hey all,

I've been working on a problem for a long time and haven't found the
answer until just now because of all of the reading I've had to do.  So,
I'll describe my problem.

I sometimes cut and paste stuff from the web into a vim file which is in
table format, but when I paste it, it has multiple spaces between each
record/field.  I took the original file as such:

                      KHOW
                           630
                                 News / Talk
                      KNUS
                           710
                                 News / Talk
                      KTLK
                           760
                                 Talk

and I've been able to remove the multiple spaces with vi by:

:%s/  *//

Which got me to:

KHOW
630
News/Talk
KNUS
710
News/Talk
KTLK
760
Talk

However, up until just a few minutes ago, I couldn't get the
records/fields to match up correctly no matter what I was reading in the
books vi, sed & awk, or Regular Expressions.  BUT, I did find my answer
in Linux in a Nutshell and my answer was paste.  So, I typed this:

paste -s -d"\t\t\n" FILENAME

This is what I got:

KHOW	630	News/Talk
KNUS	710	News/Talk
KTLK	760	Talk

The key issue for paste is the number of fields which you want the lines
to be merged into.  Such as:

paste -s -d"\t\n" FILENAME will only merge into two fields whereas:
paste -s -d"\t\t\n" FILENAME will merge into three fields

Now it's on to other issues to conquer!!

Man, am I loving Linux more and more.

Kevin





More information about the clue-tech mailing list