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.
Related
I am a newbie. I need to create wordlist with specified pattern. The pattern will look like XXXXX00000 where X are 5 english characters (different, but can be same, small from alphabet) and 00000 are 5 numbers (0-9). (There will not be some special characters like &, $, _, -...)
Can someone help me?
It will be nice, if someone will post Terminal command. For example using crunch.
Thank you.
Examples:
aklmj98765
kjgfk11137
hhhhd00110
I made a program for you, save this as anyname.py and run. copy the output.
letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
numbers = "0123456789"
for a in range(len(letters)):
for b in range(len(letters)):
for c in range(len(letters)):
for d in range(len(letters)):
for e in range(len(letters)):
for f in range(len(numbers)):
for g in range(len(numbers)):
for h in range(len(numbers)):
for i in range(len(numbers)):
for j in range(len(numbers)):
print(letters[a] + letters[b] + letters[c] + letters[d] + letters[e] + numbers[f] + numbers[g] + numbers[h] + numbers[i] + numbers[j])
crunch 10 10 -t #####%%%%% -o result.txt
github.com/adaywithtape/wlm does just about anything you want easy to use.I answered in the wrong place see description below.
I have a scenario like below:
I have a .dat file where header field name which is coming as below example:
2_a 2_b 2_c 2_d 2_e - Header
a b c d e - Data
f g h I j - Trailer
Next time
1_a 1_b 1_c 1_d 1_e -Header
c d e f g -data
b d f j k - trailer
So I want to achieve like my header record number is dynamically changing. Is there any way that I can achieve it so that I will just put the value and it will pick that value before that...like if I will input value 3 the header record will become 3_a 3_b like that....
After that my data will come and then trailer...Please suggest me the process as I am new to powershell...
If you want to create a line like
2_a 2_b 2_c 2_d 2_e
or
1_a 1_b 1_c 1_d 1_e
dynamically, you could use the string format operator, -f, like this
$index = 2
$header = "{0}_a {0}_b {0}_c {0}_d {0}_e" -f $index
this will create the first header and save it to a variable. Change the $index variable to create another string with some other number instead.
See this link for more info on its usage.
I have few similar questions about expressions. I marked them as Q1, Q2 and Q3 for convenience.
First. As stated in the docs,
Variable names in an expression are not enclosed in percent signs (except for pseudo-arrays and other double references). Consequently, literal strings must be enclosed in double quotes to distinguish them from variables.Source
As I understand, this means we should write code like this:
a = aaa
b = zzz
if (a = "aaa" or b = "bbb")
MsgBox, It works!
However, this seems also works:
a = aaa
b = zzz
if (%a% = aaa or %b% = bbb)
MsgBox, It works!
Is there some drawbacks in the second way? (Q1)
One possible drawback, which I found myself, is that second method will not work if variable contains only digits. This will not work:
a = 111
b = 999
if (%a% = 111 or %b% = 222)
MsgBox, It works!
Why it stopped worked now? (Q2)
And also, if variable contains only digits, there seems no need to quote it's value in expression:
a = 111
if (a = "111") ; Also works for a = "aaa"
MsgBox, It works!
a = 111
if (a = 111) ; It will not work for a = "aaa". We forced to us quote signs if var contains letters.
MsgBox, It works too.
Why second way (if (a = 111)) works and should or should not we avoid it? (Q3).
(Q1)
If a variable is enclosed in percent signs within an expression (in your example %a%), whatever that variable contains is assumed to be the name or partial name of another variable.
This also works
a = aaa
b = zzz
if (%a% = a or %h% = cc)
MsgBox, It works!
because the values of the vars %a% and %h% are not specified.
(Q2)
If both var and value are purely numeric, they will be compared as numbers rather than as strings.
Otherwise, they will be compared alphabetically as strings (that is, alphabetical order will determine whether var is greater, equal, or less than value).
(Q3)
Only literal strings must be enclosed in double quotes.
If the variable contains only digits, there is no need to quote.
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
I have the following code, and i am wanting to store the entire line that contains the matching expression, but currently i am able to store only the expression itself.
expr='\hello';
fileread = regexp(filetext, expr, 'match');
fid = fopen('data.txt', 'wt');
fprintf(fid, '%s\n',fileread{:});
suppose my file contains:
Hello,my name is X
X hello
Not this line
my file data.txt stores
hello
hello
instead of the entire line containing the expression.
desired data.txt
Hello,my name is X
X hello
what am i doing wrong?
Based on the way you are interacting with the regexp function I will assume you have all the file text in a single variable. Let's imagine that variable takes the following form:
my name is hello there
Hello,my name is X
X hello
Not this line
For your reference, I've constructed this variable using sprintf
string = sprintf('my name is hello there\nHello,my name is X\n X hello\n Not this line')
You can extract the lines which have hello with the following regexp:
[~,~,~,d] = regexp(string, '.*?[H|h]ello.*?\n')
The results can be retrieved from the cell array with:
>> d{1}
ans =
my name is hello there
>> d{2}
ans =
Hello,my name is X
>> d{3}
ans =
X hello
Note that I used a couple of lazy quantifiers .*?, check out Laziness Instead of Greediness at this link if you would like to learn more: http://www.regular-expressions.info/repeat.html
What you're doing wrong is not using the MATLAB regexp function correctly. If you look under "Return Substrings using 'match' Keyword" on this site, you will see that the result you got is what is expected for what your code stated (it returns the parts of the input string that match the regular expression you supplied). I was going to post a suggestion, but someone beat me to it ;-). Good luck.