I am trying to use C-u M-x align-regex to align these lines
a, b, c, d
aa, bb, cc, dd
aaaaaaaaaaaaaaaaa , bbbbbbbbbbbbbbbbbbbbbbbb , cccccc, ddddddddddddd
aaa , bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb , c, dddd
(note: indent-tabs-mode is set to nil (ie use spaces not tabs)
I tried C-u M-x align-regex:
Complex align using regexp: \(,\)[Ret]
Parenthesis group to modify (justify if negative): 1
Amount of spacing (or column if negative): 1
Repeat throughout line? (y or n) y
It resulted in this:
a, b, c, d
aa, bb, cc, dd
aaaaaaaaaaaaaaaaa , bbbbbbbbbbbbbbbbbbbbbbbb , cccccc, ddddddddddddd
aaa , bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb , c, dddd
Was expecting the "," to be aligned, and whitespace to be added/removed as necessary
like this:
a, b, c, d
aa, bb, cc, dd
aaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbb, cccccc, ddddddddddddd
aaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, c, dddd
Is this some kind of bug or is it that I did not specify the options correctly?
Thanks
Ian
Related
I'm trying to write Checksum Algorithm using MARIE.js, but I'm stuck on doing 1's complement.
I saw other assembly languages have CMA code, but I couldn't find that information on MARIE.
Thus, I typed G that opcode is 2F to find the checksum byte but the output is not what I expected.
What did I miss or do something wrong?
Input /Takes user input
Store A /Stores user input to A
Input /Takes user input
Store B /Stores user input to B
Input /Takes user input
Store C /Stores user input to C
Input /Takes user input
Store D /Stores user input to D
Load A /Load A to AC
Add B /Add B to A
Add C /Add C to B
Add D /Add D to C
Subt F /Subtract F from Sum of data 1,2,3,4
Store E /Sum of data 1,2,3,4 ignoring carry
Subt G
/Add ONE
Output /Print checksum byte
HALT /End program
/Variable decleration
A, HEX 0 /Data 1
B, HEX 0 /Data 2
C, HEX 0 /Data 3
D, HEX 0 /Data 4
E, HEX 0 /Checksum byte
F, HEX 100 /Ignore carry
G, HEX 2F
ONE, DEC 1
Two's complement, -n, is defined as one's complement + 1, e.g. ~n + 1
Therefore, since MARIE has subtraction you can make two's complement (e.g. 0-n) and subtracting 1 from that will yield one's complement, ~n.
Expected Input
A B C
C A B
C C A
C A A
A A B
Expected Output
A B C
C A B
C C B
C B B
A A B
Output
B B C
C B B
C C B
C B B
A A B
I am trying to make this command work but it's not working.
# '/C/s/A/B' file > newfile
sed '3,$ /C/s/A/B' file > newfile
You will beed to use { ...; } to group sed commands for the line ranges you want and put a ; before } so make sure BSD/POSIX sed can work with that.
You may use this sed:
sed '3,$ { /C/ s/A/B/g; }' file > newfile
cat > newfile
A B C
C A B
C C B
C B B
A A B
With your shown samples, please try following awk code. Simple explanation would be, checking condition if line number is more than 3 or equal to 3 AND line contains C then globally substitute all occurrences of A with B and print edited/non-edited lines.
awk 'FNR>=3 && /C/{gsub(/A/,"B")} 1' Input_file
This might work for you (GNU sed):
sed '3,$!b;/C/y/A/B/' file
If the line number is not between 3 and the end-of-the-file, bail out.
Otherwise, for lines containing C, translate A's to B's.
N.B. If A's and B's are true words, use s/A/B/g.
Almost trivial to ask, but i'm confused and curious. Why is the "\t" special character not applying a tab for:
It looks like the "\t" character only applied a single space rather than a tab. However if I move the "\t" character over, it applies it like so
Any ideas?
'Tabs' are actually applied. Tabs' width is usually determined by your terminal. In StackOverflow's (web-fronted) case, it's 4 characters wide. Output goes like this.
b
a b
aa b
aaa b
aaaa b
aaaaa b
aaaaaa b
aaaaaaa b
aaaaaaaa b
aaaaaaaaa b
aaaaaaaaaa b
aaaaaaaaaaa b
aaaaaaaaaaaa b
aaaaaaaaaaaaa b
aaaaaaaaaaaaaa b
aaaaaaaaaaaaaaa b
Not really an answer but explains the problem well.
I am working on a programming problem set that requires me to take space delimited input and output it through a function. I thought that if I added commas then I could make iterating through my function better.
I tried to use f.replace() and f.open('input.txt', 'r+') but it appended my output to the end of the file. I used f.open('input.txt', 'w') but I got an error that told me that the file was unreadable.
def commasv():
f = open('input.txt', 'r+')
for x in f:
x = x.split(' ', 2)
f.write()
f.close()
My sample input was 'C D E'. I expected the output to be 'C, D, E, ', but the output was 'C D EC, D, E, '
I have a data file like the following:
----------------------------
a b c d e .............
A B C D E .............
----------------------------
But I want it to be in the following format:
----------------------------
a A
b B
c C
d D
e E
...
...
----------------------------
What is the quickest way to do the transformation in Vim or Perl?
Basically :.s/ /SpaceCtrl+vEnter/gEnterjma:.s/ /Ctrl+vEnter/gEnterCtrl+v'axgg$p'adG will do the trick. :)
OK, let's break that down:
:.s/ /Ctrl+vEnter/gEnter: On the current line (.), substitute (s) spaces (/ /) with a space followed by a carriage return (SpaceCtrl+vEnter/), in all positions (g). The cursor should now be on the last letter's line (e in the example).
j: Go one line down (to A B C D E).
ma: Set mark a to the current position... because we want to refer to this position later.
:.s/ /Ctrl+vEnter/gEnter: Do the same substitution as above, but without the Space. The cursor should now be on the last letter's line (E in the example).
Ctrl+v'a: Select from the current cursor position (E) to mark a (that we set in step 3 above), using the block select.
x: Cut the selection (into the " register).
gg: Move the cursor to the first line.
$: Move the cursor to the end of the line.
p: Paste the previously cut text after the cursor position.
'a: Move the cursor to the a mark (set in step 3).
dG: Delete everything (the empty lines left at the bottom) from the cursor position to the end of the file.
P.S. I was hoping to learn about a "built-in" solution, but until such time...
Simple re-map of the columns:
use strict;
use warnings;
my #a = map [ split ], <>; # split each line on whitespace and store in array
for (0 .. $#{$a[0]}) { # for each such array element
printf "%s %s\n", $a[0]->[$_], $a[1]->[$_]; # print elements in order
}
Usage:
perl script.pl input.txt
Assuming that the cursor is on the first of the two lines, I would use
the command
:s/ /\r/g|+&&|'[-;1,g/^/''+m.|-j