From: Skip Montanaro <skip.montanaro@gmail.com>
To: Angus Comber <anguscomber@gmail.com>
Cc: help-gnu-emacs@gnu.org
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 [thread overview]
Message-ID: <CANc-5UzTy6ZRkAjiqwgsToyyEO3kfRzy+vQUDWeXZ0pqxHnYnw@mail.gmail.com> (raw)
In-Reply-To: <0b6f7632-f4c0-47c9-b3fb-b5d554c358c1@googlegroups.com>
> 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:
wtr.writerow(list(reversed(row)))
Skip Montanaro
next prev parent reply other threads:[~2017-05-17 1:17 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-16 16:34 Is it possible to move a column where column on right is variable width Angus Comber
2017-05-16 17:38 ` Kaushal Modi
2017-05-16 19:11 ` Joost Kremers
2017-05-16 19:23 ` Emanuel Berg
2017-05-16 19:32 ` Kaushal Modi
2017-05-16 18:51 ` Tomas Nordin
2017-05-16 19:14 ` Emanuel Berg
2017-05-16 21:56 ` Tomas Nordin
2017-05-17 1:17 ` Skip Montanaro [this message]
2017-05-17 2:05 ` Ben Bacarisse
2017-05-17 6:22 ` Loris Bennett
2017-05-18 6:17 ` hector
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CANc-5UzTy6ZRkAjiqwgsToyyEO3kfRzy+vQUDWeXZ0pqxHnYnw@mail.gmail.com \
--to=skip.montanaro@gmail.com \
--cc=anguscomber@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).