Why is \t not being applied to this string? - swift

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.

Related

How to find 1's complement in MARIE?

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.

sed: Replace word A with B from line 3 till last line only on line which contains word C

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.

Searching for a Name in a Global using a Partial Name

I created a name global and I am trying to print out a matching name by using only using the same characters that the name starts with. Example: Enter Sm and return the value Smith, John A.
I created this:
N prompt,val
S prompt="Enter a name (LAST,FIRST MI): "
F W !,prompt R val Q:val="" D
. I val'?1.A1",".1" "1.A.1(1" "1A) W !,"Invalid name"
. E S ^ZNAME(val)=""
F S val=$O(^ZNAME(val)) Q:val="" D
. W !,"You entered: ",val
Q
I entered two names and got the desired result.^ZNAME("MITCHELL, DAVID J")^ZNAME ("SMITH, JOHN A").
I want to to be able to read a partial name and it search the ^ZNAME and return the value it matches. In this case read "Sm" and return "Smith, John A."
N partial,val
S partial="Enter a name or partial name: "
F W !,partial R val Q:val="" D
. W !,$O(^ZNAME("val"))
Q
When I enter "Sm" from the read command it loops back to Enter a name or partial name instead of giving me the desired result of Smith, John A. I am missing something I know it, but a little burnt out. Any help will be great thank you!
You've got double quotes around val:
. W !,$O(^ZNAME("val"))
Q
So it is trying to write the value at ^ZNAME("val") which there isn't one. Remove the double quotes and it should work.

emacs align-regex fails for wide data

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

Remove only single spaces in text file with sed, perl, awk, tr or anything

I have a rather large text file where there is an extra space between every character;
I t l o o k s l i k e t h i s .
I'd like to remove those extra characters so
It looks like this.
via the Linux terminal.
I can't seem to find anyway to do this without removing all of the whitespaces. I'm willing to try any solution at this point. I'd appreciate any nudge in the right direction.
$ echo 'I t l o o k s l i k e t h i s . ' | sed 's/\(.\) /\1/g'
It looks like this.
Are you certain that the intermediate characters are spaces? It is most likely that this is a UTF-16 file.
I suggest you use a capable editor to open it as such and convert it to UTF-8.
An awksolution
echo "I t l o o k s l i k e t h i s ." | awk '{for (i=1;i<=NF;i+=2) printf $i;print ""}' FS=""
It looks like this.
As long as it's every other character you want to get rid of, you can use python.
>>> s = "I t l o o k s l i k e t h i s ."
>>> print s[0::2]
It looks like this.
If you wanted to do this for the text file, do the following:
with open("/path/to/file.txt") as f:
f = f.readlines()
with open("/path/to/new.txt") as g:
for i in f:
g.write(str(i)[0::2]+"\n")
perl -pe 's|(\s+)| " "x (length($1)>1) |ge' file