What I'm trying to do is getting a record from a table and comparing it against the text in an element in the web UI.
I exec into the docker and run the command to pull out the top record which works fine
+++ docker exec -it 60493033cec6 /bin/sh -c 'mysql -uroot -ppassword -Bse "use requestdb; select REQUEST_ID from infra_active_requests limit 1;"'
The echo command for the above outputs the below:-
++ req_id=$'0327902d-6346-4c61-94b2-9da532bc7ef3\r'
++ echo Record: $'0327902d-6346-4c61-94b2-9da532bc7ef3\r'
Record: 0327902d-6346-4c61-94b2-9da532bc7ef3 notice there is no \r here
++ export $'req_id=0327902d-6346-4c61-94b2-9da532bc7ef3\r'
++ req_id=$'0327902d-6346-4c61-94b2-9da532bc7ef3\r' `// \r included in the string here.
AND in the tests I am using the below statement to compare the strings
${result} Get Text xpath = //*[#id="mat-tab-content-0-0"]/div/mat-table/mat-row[1]/mat-cell[1]/a
Should be equal as Strings ${result} ${REQ_ID} //REQ_ID has the request id created before
${REQ_ID} = Fetch From Left ${REQ_ID} \r ` // to remove the \r
I am trying to set the value of the outcome from the db query on to ${RESULT} using
${REQ_ID} = Fetch From Left ${REQ_ID} \r
Am i doing this right? The String library is imported
The error I get is:-
1. No keyword with name 'Fetch From Left ${REQ_ID} \r' found.
or
2. 0327902d-6346-4c61-94b2-9da532bc7ef3 != 0327902d-6346-4c61-94b2-9da532bc7ef3 ///when run without the fetch from left command
In the Fetch from left keyword there should be at least 2 spaces between the keyword and the arguments. In your code there seems to be only one between Fetch From Left, ${REQ_ID} and \r. This is why you get the No keyword with name 'Fetch From Left ${REQ_ID} \r' found. error.
Also, if you're not able to compare the strings due to the \r character, you should compare the string after removing /r. Exchange the positions of line numbers 2 and 3.
${result} Get Text xpath = //*[#id="mat-tab-content-0-0"]/div/mat-table/mat-row[1]/mat-cell[1]/a
${REQ_ID} = Fetch From Left ${REQ_ID} \r // to remove the \r
Should be equal as Strings ${result} ${REQ_ID} //REQ_ID has the request id created before
I'm almost sure this should work. Do comment if it doesn't.
Related
I have a list of file names (about 4000).
For example:
A-67569
H-67985
J-87657
K-85897
...
I need to put an asterisk before and after each file name. And then make it a line format.
Example:
*A-67569* *H-67985* *J-87657* *K-85897* so on...
Note that there is a space between filenames.
Forgot to mention, I'm trying to do this with Notepad++
How can I do it?
Please advise.
Thanks
C# example for list to string plus edits
List<string> list = new List<string> { "A - 67569"), "H-67985", "J-87657", "K-85897"};
string outString = "";
foreach(string item in list)
{
outString += "*" + item + "* ";
}
content of outstring: *A - 67569* *H-67985* *J-87657* *K-85897*
Use the Replace of your Notedad++ (Search > Replace..)
Select Extended (\n \r \t \0 \x...) on the bottom of the Replace window
In the field Find what write '\r\n' and in the field Replace with write * *
Replace all
Note, that you should manually place the single asterisk before the first and after the last words.
If this won't work, in step 2. instead of \r\n try to use only \n or \r.
You can use Regular expression in the search Mode.
Find what:
(\S+)(\R|$)
Replace with:
*$1
Note the space after de number one
For the archive
A-67569
H-67985
J-87657
K-85897
Output:
*A-67569 *H-67985 *J-87657 *K-85897
Explication of regex:
(\S+) Mean find one or more caracters is not a blank.
(\R|$) Mean find any end of line or end of file
(\S+)(\R|$) Mean find any gorup of caracters not blank ho end with end of line or end of file.
Explication of Replace with
When you use the $ simpbol, you are using a reference to the groups finded, $1 is the first group, in this case the group (\S+).
I have a shell script script.sh, and a sql script modify_database.sql
In script.sh, I launch the sql script with some param using :
sqlplus user/password ... #modify_database.sql « param_id » « param_newValue »
And in the sql script, I get the parameters value with :
UPDATE T_TEST SET C1 = ¶m_newValue WHERE ID = ¶m_id
But I have a lot of problem with the « param_newValue » parameter.
In fact, this parameter could contain some spaces, slash, single quote and double quote character.
For example : L’avion du pilote était surnommé le « Redoutable »
I have a bunch of values to update.
Each new values are stored in a txt file, like that :
id;value
1; L’avion du pilote était surnommé le « Redoutable »
2; Another example of a « test » that’s it
How can I do to pass this param to sqlplus and set the value like that ? The quoted part is giving me a hard time :/
EDIT :
Example, in the input file I have :
123;;;"aaaa/vvvv/COD_039/fff=Avion d'office";"aaaa/vvvv/COD_039/fff=Hello d'orien";
I get this line, I do a cut command to get the first column (ID), the 4th column (to replace), and the 5th column (replacement).
I have a XML node, with a node which contain the 4th column text, and need to replace by the 5th column content.
So I do :
sqlplus -s $DBUSER/$DBPASSWORD#$DBHOST:$DBPORT/$DBSCHEMA #majConfXML.sql "$id" "$newcode"
update T_TEST set XML = updatexml(xmltype(XML_CONF),
'//A[#name="XXX"]//B[#name="YYY"]//pkValue','&2').getClobVal()
But in the param, there is some quotes.
So when I do the update request with '&2', the request is running but it does not work properly.
How can I escape/pass the param value into the updateXML request ?
Thank you
Finally, I find a problem in my bash script before the sqlplus call.
In fact, it was xargs command which I use who interpret simple quote. I simply add double quotes around each string with slash and quote in my input file.
Next, before calling sqlplus, I replace all “ ‘ “ (quote) by “ ‘’ “ (quote quote)
I'm new to bq command line, trying to run a simple query that works in UI...
bq query “select Email_Address from Contact.mailchimp_unsubscribe”
I get this error:
Error in query string: Error processing job
'aaa-dataplatform:bqjob_r41894edbc8642323_00000161bebe6574_1':
Encountered " "\u201c "" at line 1, column 1.
Was expecting: < EOF >
If I change the column name Email_Address to * the query works. However, I will need to make this an append query with a specific column list. So, need to figure out how to make the column list work.
u201c is a left double quotation mark; error message also says that it's at the line 1, column 1. So the quotation mark is passed to BQ with the query text. In the command line, try using neutral double or single quotation.
When I use the following code, I only seem to print the last results from my array. I think it has something to do with my like clause and the % sign. Any ideas?
my #keywords = <IN>;
my #number = <IN2>;
foreach my $keywords (#keywords)
{
chomp $keywords;
my $query = "select *
from table1 a, table2 b
where a.offer = b.offer
and a.number not in (#number)
and a.title like ('%$keywords%')";
print $query."\n";
my $sth = $dbh->prepare($query)
or die ("Error: Could not prepare sql statement on $server : $sth\n" .
"Error: $DBI::errstr\n");
$sth->execute
or die ("Error: Could not execute sql statement on $server : $sth\n" .
"Error: $DBI::errstr\n");
while (my #results = $sth->fetchrow_array())
{
print OUT "$results[0]\t$results[1]\t$results[2]\t$results[3]\t",
"$results[4]\t$results[5]\t$results[6]\t$results[7]\t",
"$results[8]\n";
}
}
close (OUT);
I'm guessing that your IN file was created on a Windows system, so has CRLF sequences (roughly \r\n) between the lines, but that you're running this script on a *nix system (or in Cygwin or whatnot). So this line:
chomp $keywords;
will remove the trailing \n, but not the \r before it. So you have a stray carriage-return inside your LIKE expression, and no rows match it.
If my guess is right, then you would fix it by changing the above line to this:
$keywords =~ s/\r?\n?\z//;
to remove any carriage-return and/or newline from the end of the line.
(You should also make the changes that innaM suggests above, using bind variables instead of interpolating your values directly into the query. But that change is orthogonal to this one.)
Show the output of the print $query and maybe we can help you. Better yet, show the output of:
use Data::Dumper;
$Data::Dumper::Useqq=1;
print Dumper($query);
Until then, your comment about "replaces the an of and" makes me think your input has carriage returns, and the use of #number is unlikely to work if there's more than one.
This wasn't a problem in 0.9.2, but in 0.10, when I try to access a key in a map that has a dollar sign in it, I get hammered with errors that I haven't defined the variable. Specifically:
blah = FOREACH meh GENERATE source, json_post_id#'$id' AS post_id;
returns
Undefined parameter : id
That's fine and makes sense, but when I amend it to:
blah = FOREACH meh GENERATE source, json_post_id#'\$id' AS post_id;
I get:
Unexpected character '$'
Ideas?
[Edit] Forgot to mention: have tried with 2 backslashes and 3 backslashes as well. No dice. [/Edit]
Based on a response to your Mail Archive Posting, it looks like the behavior will be "different when using Grunt shell and running it as a script."
Input file
cheolsoo#localhost:~/workspace/pig-svn $cat 1.txt $id,a
Grunt shell
The $ with no backslash works:
grunt> A = LOAD '1.txt' USING PigStorage(',') AS (k:chararray,
v:chararray); grunt> B = FOREACH A GENERATE TOMAP(k, v) AS M; grunt> C
= FOREACH B GENERATE M#'$id'; grunt> DUMP C; (a)
Script
The $ with a single backslash works:
cheolsoo#localhost:~/workspace/pig-svn $cat test.pig A = LOAD '1.txt'
USING PigStorage(',') AS (k:chararray, v:chararray); B = FOREACH A
GENERATE TOMAP(k, v) AS M; C = FOREACH B GENERATE M#'\$id'; DUMP C;
cheolsoo#localhost:~/workspace/pig-svn $./bin/pig -x local test.pig
(a)
Also, from Pig problem with split string(STRSPLIT), have you tried either of the following.
Correctly escaping the character u0024. Test single using single or double quotes to see if that makes a difference. This answer shows that the single quote makes a difference which you have but it's worth mentioning.
Alternatively, although related, break the loop into a block.
blah = FOREACH meh {
GENERATE source, json_post_id#'$id' AS post_id;
}
It looks like you are concatenating an id. Make sure you are not suppose to be using CONCAT(). http://pig.apache.org/docs/r0.10.0/func.html#concat
According to the Class PigStorage documentation (Pig 0.10.0 API):
A load function that parses a line of input into fields using a character delimiter. The default delimiter is a tab. You can specify any character as a literal ("a"), a known escape character ("\t"), or a dec or hex value ("\u001", "\x0A").