Artificial intelligent assistant

Filter rows of a file by list of a second file `file1.tabular` contains information of 'elements' over 3 columns. element1 235 oval red \ element2 334 oval red \ element3 356 rectangular blue `file2.txt` contains a single column element1\ element3 I want to filter `file1.tabular` and save them as `file3.tabular`, which will contain only the elements in `file2.txt`, but with all 3 column information in `file1.tabular`, such as element1 235 oval red\ element3 356 rectangular blue Would there be an command to solve this on Ubuntu? I would appreciate an expert help. Thanks

You may be looking for


grep -f file2.txt file1.tabular > file3.tabular


The `-f` option instructs `grep` to read the patterns to look for from `file2.txt`. It applies the search to `file1.tabular` and redirects output to `file3.tabular`.

Note that I assume there are not really "line continuation" escapes ( the `\` at the end of all lines) in your files.

* * *

Note: As usual with regular expression-based searches, you need to be careful when formulating the content of `file2.txt`.

* Any characters special to RegExes that you want to be matched literally need escaping.
* Also, `grep` will by default show partial matches (i.e. one pattern matching only a sub-string of a word in `file1.tabular`). To alleviate, you can use the `-w` switch to allow only "full-word" matches.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 98d4e190be09fd7ca743dd3e86d09d97