[LINUX] How to use the grep command and frequent samples

grep command

A command to search for matching lines in a regular expression

syntax

grep [option] pattern [file] ex: grep -n abc aaa.txt

importance

★★★★★(5/5) Required. If you don't remember this, it will hinder your daily work.

Options

Options you want to remember

Options you want to remember if you can

Options that you don't have to remember (for each person)

sample

appendix

If you want to perform an AND search with grep

grep aaa sample.csv | grep bbb

→ Narrow down to those that contain aaa, and further narrow down to those that contain bbb

If you want to do an OR search with grep

grep -e aaa-e bbb sample.csv

→ Repeat the -e option multiple times. Extract the line containing aaa and the line containing bbb.

I want to extract the one with a specific file name

ls ./ | grep aaa

→ Extract files containing aaa (file name) in the current directory (current directory).

I want to extract a file that contains specific content

grep aaa -rl ./

→ Files in the current directory (current directory) that contain aaa

I want to find out the latest command containing a specific character string from the history of executed commands.

history | grep aaa | tail

→ Extract commands including aaa from history commands. Narrow down to the last 5 with tail.

Summary

The grep command is required, so it's a good idea to remember it!

Recommended Posts

How to use the grep command and frequent samples
How to use the Linux grep command
[Linux] How to use the echo command
How to use the grep command to recursively search directories and files to a specified depth
How to use the generator
How to use the decorator
Linux user addition, how to use the useradd command
How to use argparse and the difference between optparse
(Remember quickly) How to use the LINUX command line
How to use the zip function
How to use the optparse module
How to install and use Tesseract-OCR
How to use MBDyn (command setting)
How to use .bash_profile and .bashrc
How to install and use Graphviz
How to use the ConfigParser module
How to use the Spark ML pipeline
How to install and use pandas_datareader [Python]
[EC2] How to install chrome and the contents of each command
How to calculate Use% of df command
[EC2] How to install and download chromedriver from the command line
python: How to use locals () and globals ()
How to use CUT command (with sample)
How to use Python zip and enumerate
How to use the IPython debugger (ipdb)
How to use Python with Jw_cad (Part 2 Command explanation and operation)
How to use is and == in Python
[Introduction to Python] How to use the Boolean operator (and ・ or ・ not)
How to use pandas Timestamp and date_range
3 best ways to use the less command
[Python] How to use the enumerate function (extract the index number and element)
How to use the C library in Python
How to use lists, tuples, dictionaries, and sets
How to use the graph drawing library Bokeh
How to use the Google Cloud Translation API
How to use the NHK program guide API
[Algorithm x Python] How to use the list
[Python] How to use hash function and tuple.
How to install Cascade detector and how to use it
How to use xml.etree.ElementTree
How to use Python-shell
How to use tf.data
How to use Seaboan
How to use image-match
How to use shogun
How to use Pandas 2
How to use Virtualenv
How to use numpy.vectorize
How to use pytest_report_header
How to use partial
How to use Bio.Phylo
How to use x-means
How to use WikiExtractor.py
How to use IPython
How to use virtualenv
How to use Matplotlib
How to use iptables
How to use numpy
How to use TokyoTechFes2015
How to use venv
How to use dictionary {}