I have a .dat file which looks like this:
NGC0448 A3D:2010B g:o,r:o,i:o
NGC0474 A3D:2011A,2013A g:o,r:o,i:o,u:o
Now I want to align them to be in this form:
NGC0448 A3D:2010B g:o,r:o,i:o
NGC0474 A3D:2011A,2013A g:o,r:o,i:o,u:o
I tried with C-u M-X align
and M-x align-regexp
with=
but neither works. Can someone come up with a solution?
The \(\s-*\)\s- string is the regular expression that is used to align on, and the final \s- in that string tells emacs to align on a whitespace character.
First, we align the text. Select the text first, then press Ctrl + u then call align-regexp , with the regexp . * \([0-9,]+\). * then choose -1 for group, 1 for spacing, and n for repeat.
Why did you try to align on =
?? There isn't a single =
in that example text.
Assuming your example is representative, you can align on the spaces. I'll use \s-
(whitespace syntax) instead of an actual space, as the latter is harder to see.
C-uM-x align-regexp
RET
\(\s-*\)\s-
1
3
y
If you only want to align in the display and would prefer not to modify the file, you can try csv-mode
(available in GNU ELPA). You'll have to specify SPC as the separator (by default it's comma or TAB), but you can then use the menu to tell the mode to align the columns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With