[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is it possible to move a column where column on right is variable wi

From: Skip Montanaro
Subject: Re: Is it possible to move a column where column on right is variable width
Date: Tue, 16 May 2017 20:17:59 -0500

> I tried using rectangles, eg:
> set mark at top left buffer, C-space
> select area, ie selected area is all of Symbols column
> Then c-x r k to remove the symbols from 1st column and save to the rectangle 
> kill ring.
> then I replace $ with tab.

I think you were on the right track with rectangles, but I I would cut
out the ragged description and move it in front of the symbols. So,
using your example:

* place point over the "H" in "HAMMERSON"
* set mark
* move point after the "USD" at the end of the first line.
* insert a single tab (perhaps need C-q C-i).
* cut the rectangle
* move point to the start of the buffer
* yank the rectangle.

If the first line isn't the longest, continue entering TABs until you
are past the length of the longest line. You will probably have to
collapse multiple whitespace characters into one to get your TAB
separator back.

All the trailing whitespace will disappear if you have this set:

(add-hook 'before-save-hook 'delete-trailing-whitespace)

You might want to make that mode-specific.

Other people have offered non-Emacs solutions as well. I offer two.

My favorite for such simple things is awk:

awk -F ' \t' '{printf("%s\t%s\n", $2, $1)}'< description.txt

If I wanted to place the algorithm into a file (you won't just be
downloading a single file of stock data :-), either toss the awk
command into a shell script, or write a short little Python script:

#!/usr/bin/env python

import sys, csv

rdr = csv.reader(sys.stdin, delimiter="\t")
wtr = csv.writer(sys.stdout, delimiter="\t")

for row in rdr:

Skip Montanaro

reply via email to

[Prev in Thread] Current Thread [Next in Thread]