How to use grep efficiently?

If you have xargs installed on a multi-core processor, you can benefit from the following just in case someone is interested. Environment: Processor: Dual Quad-core 2.4GHz Memory: 32 GB Number of files: 584450 Total Size: ~ 35 GB Tests: 1. Find the necessary files, pipe them to xargs and tell it to execute 8 instances. … Read more

Search a text file and print related lines in Python?

searchfile = open(“file.txt”, “r”) for line in searchfile: if “searchphrase” in line: print line searchfile.close() To print out multiple lines (in a simple way) f = open(“file.txt”, “r”) searchlines = f.readlines() f.close() for i, line in enumerate(searchlines): if “searchphrase” in line: for l in searchlines[i:i+3]: print l, print The comma in print l, prevents extra … Read more

Search and get a line in Python

you mentioned “entire line” , so i assumed mystring is the entire line. if “token” in mystring: print(mystring) however if you want to just get “token qwerty”, >>> mystring=””” … qwertyuiop … asdfghjkl … … zxcvbnm … token qwerty … … asdfghjklñ … “”” >>> for item in mystring.split(“\n”): … if “token” in item: … … Read more

Search and delete multiple lines

The :global command is your friend – learn it well. It lets you run arbitrary :ex commands on every line that matches a regex. It abbreviates to :g. To delete all lines that match “George Bush”: :g/George Bush/ d The command that follows can have its own address/range prefix, which will be relative to the … Read more

Git search all diffs

git log is generally the command to use when examining commit history. git log –grep can be used to search for regular expressions in the commit message. What you are after is git log -S which searches the commit content simply or git log -G which searches it with a regular expression: -S<string> Look for … Read more

Look at each character in a string

string foo = “hello world”, bar = string.Empty; foreach(char c in foo){ bar += c; } Using StringBuilder: string foo = “hello world”; StringBuilder bar = new StringBuilder(); foreach (char c in foo) { bar.Append(c); } Below is the signature of the String class: [SerializableAttribute] [ComVisibleAttribute(true)] public sealed class String : IComparable, ICloneable, IConvertible, IComparable<string>, … Read more

How to implement a Keyword Search in MySQL?

For a single keyword on VARCHAR fields you can use LIKE: SELECT id, category, location FROM table WHERE ( category LIKE ‘%keyword%’ OR location LIKE ‘%keyword%’ ) For a description you’re usually better adding a full text index and doing a Full-Text Search (MyISAM only): SELECT id, description FROM table WHERE MATCH (description) AGAINST(‘keyword1 keyword2’)

ElasticSearch – Searching For Human Names

First, I recreated your current configuration in Play: https://www.found.no/play/gist/867785a709b4869c5543 If you go there, switch to the “Analysis”-tab to see how the text is transformed: Note, for example that Heaney ends up tokenized as [hn, heanei] with the search_analyzer and as [HN, heanei] with the index_analyzer. Note the case-difference for the metaphone-term. Thus, that one is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)