I am trying to make a simple page with search bar when a user searches a particular word the data is to be pulled from google spread sheets
var queryString = encodeURIComponent('SELECT A, B, C, D, E,F where A like "%<?php echo $search; ?>%" or B like "%<?php echo $search; ?>%" or C like "%<?php echo $search; ?>%" or D like "%<?php echo $search; ?>%" or E like "%<?php echo $search; ?>%" label A "Sr no", B "Product name", C "Technical name", D "Category", E "Seller Name", F "Price" ');
This works while
var queryString = encodeURIComponent('SELECT A, B, C, D, E,F where upper(A) like upper("%<?php echo $search; ?>%") or B like upper("%<?php echo $search; ?>%") or C like upper("%<?php echo $search; ?>%") or D like upper("%<?php echo $search; ?>%") or E like upper("%<?php echo $search; ?>%") label A "Sr no", B "Product name", C "Technical name", D "Category", E "Seller Name", F "Price" ');
This does not. Just trying to make the query case insensitive.
what am I doing wrong here?
looks like you just need to add upper to the rest of the columns
you added upper(A) for column A
but not for the rest of the columns -- B,C,D, & E
i.e.
B like upper("%<?php echo $search; ?>%")
vs.
upper(B) like upper("%<?php echo $search; ?>%")
second line from question
var queryString = encodeURIComponent('SELECT A, B, C, D, E,F where upper(A) like upper("%<?php echo $search; ?>%") or B like upper("%<?php echo $search; ?>%") or C like upper("%<?php echo $search; ?>%") or D like upper("%<?php echo $search; ?>%") or E like upper("%<?php echo $search; ?>%") label A "Sr no", B "Product name", C "Technical name", D "Category", E "Seller Name", F "Price" ');
change to this...
var queryString = encodeURIComponent('SELECT A, B, C, D, E,F where upper(A) like upper("%<?php echo $search; ?>%") or upper(B) like upper("%<?php echo $search; ?>%") or upper(C) like upper("%<?php echo $search; ?>%") or upper(D) like upper("%<?php echo $search; ?>%") or upper(E) like upper("%<?php echo $search; ?>%") label A "Sr no", B "Product name", C "Technical name", D "Category", E "Seller Name", F "Price" ');
Related
Consider the following variable:
clear
input str18 string
"abc bcd cde"
"def efg fgh"
"ghi hij ijk"
end
I can use the regexm() function to extract all occurrences of abc, cde and def:
generate new = regexm(string, "abc|cde|def")
list
|string new |
|--------------------|
| abc bcd cde 1 |
| def efg fgh 1 |
| ghi hij ijk 0 |
How can I get the following?
|string wanted |
|--------------------------|
| abc bcd cde abc cde |
| def efg fgh def |
| ghi hij ijk |
This question is an extension of the one answered here:
Create new string variable with partial matching of another
I read this as your
Having a list of allowed words.
Wanting the words in a string that occur among the allowed words.
It is fashionable to seek a fancy regular expression solution for such problems, but your example at least yields to a plain loop over the words that exist. Be aware, however, that inlist() has advertised limits.
clear
input str18 string
"abc bcd cde"
"def efg fgh"
"ghi hij ijk"
end
generate wanted = ""
generate wc = wordcount(string)
summarize wc, meanonly
quietly forvalues j = 1/`r(max)' {
replace wanted = wanted + " " + word(string, `j') if inlist(word(string, `j'), "abc", "cde", "def")
}
replace wanted = trim(wanted)
list
+----------------------------+
| string wanted wc |
|----------------------------|
1. | abc bcd cde abc cde 3 |
2. | def efg fgh def 3 |
3. | ghi hij ijk 3 |
+----------------------------+
This is the solution using a regular expression:
clear
input str18 string
"abc bcd cde"
"def efg fgh"
"ghi hij ijk"
end
generate wanted = ustrregexra(string, "(\b((?!(abc|cde|def))\w)+\b)", " ")
replace wanted = strtrim(stritrim(wanted))
list
+-----------------------+
| string wanted |
|-----------------------|
1. | abc bcd cde abc cde |
2. | def efg fgh def |
3. | ghi hij ijk |
+-----------------------+
I have one file a.txt with contents as follow:
a aa aaa
b bb value = 11 xyz
c cc ccc
b bb value = 222 abc
d dd ddd
I have to find for string "bb". once matching line found i have to replace "value = xxx" with "value = 77"
Here, xxx is integer with any number of digit(11,222 in above case).
I have tried below perl command:
perl -n -e 'print; if (m/\bbb\b/) { s/value = (\d+)/value = 77/g; print; }' < a.txt
It gives me output as:
a aa aaa
b bb value = 11 xyz
b bb value = 77 xyz
c cc ccc
b bb value = 22 abc
b bb value = 77 abc
d dd ddd
Here i am looking for in-place replacement, instead of new line with required changes.
Basically i am expecting output as follow:
a aa aaa
b bb value = 77 xyz
c cc ccc
b bb value = 77 abc
d dd ddd
Can anyone help me here in updating my command?
Also one more quick question, can I update my above command in way so that it can search for string "bb" and only matching lines will remove the string "value = xxx" completely from this matching line.
where xxx is integer with any number of digit.
You print twice when you have a match. If you don't want to do that, don't do that :)
perl -n -e 'if (m/\bbb\b/) { s/value = (\d+)/value = 77/g; } print' < a.txt
Cleaned up:
perl -pe's/value = \K\d+/77/g if /\bbb\b/' a.txt
Based on the sample data, you might even be able to use
perl -pe's/\bbb\b.*value = \K\d+/77/' a.txt
This works:
perl -n -e 'if (m/\bbb\b/) { s/value = (\d+)/value = 77/g; print; } else {print}' < a.txt
put one print in if and one in else
Output:
$ perl -n -e 'if (m/\bbb\b/) { s/value = (\d+)/value = 77/g; print; } else {print}' < a.txt
a aa aaa
b bb value = 77 xyz
c cc ccc
b bb value = 77 abc
d dd ddd
I would like to grep (I can accept non-grep answers but it is what I am most used to for this) lines which have a range of tokens delimited by a whitespace and with the ability to ignore punctuation marks. This means that if I want three to five tokens I would get lines with three, four or fives tokens but not one, two, six or twenty tokens. I have periods at the end and sometimes commas in the middle which I things I would like to account for if possible. Also the real data is actually words so I would like an answer with clear instructions for allowing characters which are not necessarily a-zA-Z, for example the word "can't".
My data is like this:
aa .
aa bb'b , c ddd e f gg .
aa bb .
aaa bb'b cccc dddd e .
aaaa bb'b cccc , dddd .
aa bb'b cc dd e f .
aaaaa bb'b c .
I tried this:
grep -e "[a-zA-Z']* ,*\{3,5\}"
What I expected to get was this:
aaa bb'b cccc dddd e .
aaaa bb'b cccc , dddd .
aaaaa bb'b c .
With GNU grep:
grep -E "^([a-zA-Z']+ *,* ){3,5}\.$" file
Output:
aaa bb'b cccc dddd e .
aaaa bb'b cccc , dddd .
aaaaa bb'b c .
I think awk can make this task simple, because it has a variable NF that counts number of fields (separated by blanks) in each line, so:
awk 'NF >= 4 && NF <= 6' infile
I incremented its value to take into account last period. It yields:
a b c d e .
a b c d .
a b c .
EDIT: To ignore commas, use the FS variable (Field Separator) with a regular expression:
awk 'BEGIN { FS = "[[:blank:],]+" } NF >= 4 && NF <= 6' infile
It yields:
aaa bb'b cccc dddd e .
aaaa bb'b cccc , dddd .
aaaaa bb'b c .
Here's a sed example to add to the mix:
sed -n "/^\([a-zA-Z',]* \)\{3,5\}\.$/p"
Output:
aaa bb'b cccc dddd e .
aaaa bb'b cccc , dddd .
aaaaa bb'b c .
Another possibility:
awk '/aaa+/' file
aaa bb'b cccc dddd e .
aaaa bb'b cccc , dddd .
aaaaa bb'b c .
i have a pipe delimited file that looks like this:
34ab1 | aaa bbb ccc fff vf | 2015-01-01
35ab1 | aaa bbb ccc dddefd ddff ssss fff vi | 2015-01-01
i want to replace everything that starts with bbb and ends with fff.
i used this:
BEGIN {
FS = OFS = "|"
}
{
sub(/[0-9].*[0-9]/, "", $2); sub(/bbb.*fff/, "", $2);
print
}
the regex part for the numbers worked but the second part of the regex didnt.
output i want:
34ab1 | aaa vf | 2015-01-01
35ab1 | aaa vi | 2015-01-01
Use a single gsub function for both.
BEGIN {
FS = OFS = "|"
}
{
gsub(/[0-9].*[0-9]|bbb.*fff/, "", $2);
print
}
I have these lines of data. I want to just print the numbers that follows A, C and D. Is there a way to print those columns?
(((A 0.0400213 B 0.0400213 0.00737467 C 0.047396 0.03466 D 0.082056 ;
((C 0.0275027 (A 0.023266 B 0.023266 0.00423667 0.0131187 D 0.0406213 ;
((C 0.0310553 (B 0.0210907 A 0.0210907 0.00996467 0.0222647 D 0.05332 ;
((C 0.03491 (A 0.020474 B 0.020474 0.014436 0.0221067 D 0.0570167 ;
((C 0.0485573 (A 0.00938133 B 0.00938133 0.039176 0.00335133 D 0.0519087 ;
If I want to get the numbers following A
My expected out come will be :
0.0400213,
0.023266,
0.0210907,
0.020474,
0.00938133
This should work:
awk '{for(i=1;i<=NF;i++) if($i~/A|C|D/) printf $++i FS; print ""}' file
Output:
$ awk '{for(i=1;i<=NF;i++) if($i~/A|C|D/) printf $++i FS; print ""}' file
0.0400213 0.047396 0.082056
0.0275027 0.023266 0.0406213
0.0310553 0.0210907 0.05332
0.03491 0.020474 0.0570167
0.0485573 0.00938133 0.0519087
More verbose:
$ awk '{for(i=1;i<=NF;i++) if($i~/A|C|D/) { gsub(/[(]/,"",$i) ; printf $i " is " $++i FS }; print ""}' file
A is 0.0400213 C is 0.047396 D is 0.082056
C is 0.0275027 A is 0.023266 D is 0.0406213
C is 0.0310553 A is 0.0210907 D is 0.05332
C is 0.03491 A is 0.020474 D is 0.0570167
C is 0.0485573 A is 0.00938133 D is 0.0519087
Update:
$ awk '{for(i=1;i<=NF;i++)if($i~/A/){gsub(/[(]/,"",$i);print $++i}}' file
0.0400213
0.023266
0.0210907
0.020474
0.00938133
Code for GNU sed:
$sed -r 's/.*(A\s)([0]\.[0-9]+).*/\2/' file
0.0400213
0.023266
0.0210907
0.020474
0.00938133