grep return 0 if no match
The actual answer to this question is to add || true to the end of the command, e.g.: echo thing | grep x || true This will still output a 0 return code.
The actual answer to this question is to add || true to the end of the command, e.g.: echo thing | grep x || true This will still output a 0 return code.
If you’re going for efficiency: import re count = sum(1 for _ in re.finditer(r’\b%s\b’ % re.escape(word), input_string)) This doesn’t need to create any intermediate lists (unlike split()) and thus will work efficiently for large input_string values. It also has the benefit of working correctly with punctuation – it will properly return 1 as the count … Read more
To the best of my knowledge, .groups() returns a tuple of remembered groups. I.e. those groups in the regular expression that are enclosed in parentheses. So if you were to write: print re.search(r'(1)’, ‘1’).groups() you would get (‘1’,) as your response. In general, .groups() will return a tuple of all the groups of objects in … Read more
Your statement does not work, because you try to feed the data object into match, but match can only work on strings. The following expression will do what you want. The to_entries converts the object to an array of keys and values. Then we iterate over this array by using map and select all entries … Read more
Use this sed command: sed -i.old ‘/^[#*-]\{0,1\}blubb/d’ special.conf OR sed -i.old -E ‘/^[#*-]?blubb/d’ special.conf OR sed -i.old -r ‘/^[#*-]?blubb/d’ special.conf
If you want the == to work, then implement the __eq__ method in your class to perform the rich comparison. If all you want to do is compare the equality of all attributes, you can do that succinctly by comparison of __dict__ in each object: class MyClass: def __eq__(self, other) : return self.__dict__ == other.__dict__
Just turn the LIKE around SELECT * FROM customers WHERE ‘Robert Bob Smith III, PhD.’ LIKE CONCAT(‘%’,name,’%’)
Anchor it to the start and end, and match one or more characters: if re.match(“^[a-zA-Z]+$”, aString): Here ^ anchors to the start of the string, $ to the end, and + makes sure you match 1 or more characters. You’d be better off just using str.isalpha() instead though. No need to reach for the hefty … Read more
Either the query_string query or the match query would be what you’re looking for. query_string will use the special _all field if none is specified in default_field, so that would work out well. curl -XPOST ‘localhost:9200/_search?pretty’ -d ‘{ “query”: { “query_string”: { “query”: “abc” } } }’ And with match you can just specify the … Read more