Find a value in a list [duplicate]

As for your first question: “if item is in my_list:” is perfectly fine and should work if item equals one of the elements inside my_list. The item must exactly match an item in the list. For instance, “abc” and “ABC” do not match. Floating point values in particular may suffer from inaccuracy. For instance, 1 … Read more

How can I find all files containing specific text (string) on Linux?

Do the following: grep -rnw ‘/path/to/somewhere/’ -e ‘pattern’ -r or -R is recursive, -n is line number, and -w stands for match the whole word. -l (lower-case L) can be added to just give the file name of matching files. -e is the pattern used during the search Along with these, –exclude, –include, –exclude-dir flags … Read more

grep without showing path/file:line

No need to find. If you are just looking for a pattern within a specific directory, this should suffice: grep -hn FOO /your/path/*.bar Where -h is the parameter to hide the filename, as from man grep: -h, –no-filename Suppress the prefixing of file names on output. This is the default when there is only one … Read more

Batch script to replace PHP short open tags with

don’t use regexps for parsing formal languages – you’ll always run into haystacks you did not anticipate. like: <? $bla=”?> now what? <?”; it’s safer to use a processor that knows about the structure of the language. for html, that would be a xml processor; for php, the built-in tokenizer extension. it has the T_OPEN_TAG … Read more

tech