Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

linux grep

# EXAMPLE 1: look for any files (with names ending in ".c++") for the text "::MethodA("
grep "::MethodA(" *.c++

# EXAMPLE 2: display only the matching file names (not the row too) of the matches
grep -l "MethodA(" *.c++

# SYNTAX
# grep [optional-filters] "<your-string-to-search>" <files-to-search>


# OPTIONAL-FILTERS
# +--------+----------------------------------------------------------------------------+
# | OPTION |  DESCRIPTION                                                               |
# +--------+----------------------------------------------------------------------------+
# |  -e    |  pattern                                                                   |
# |  -i    |  Ignore uppercase vs. lowercase.                                           |
# |  -v    |  Invert match.                                                             |
# |  -c    |  Output count of matching lines only.                                      |
# |  -l    |  Output matching files only.                                               |
# |  -n    |  Precede each matching line with a line number.                            |
# |  -b    |  A historical curiosity: precede each matching line with a block number.   |
# |  -h    |  Output matching lines without preceding them by file names.               |
# |  -s    |  Suppress error messages about nonexistent or unreadable files.            |
# |  -x    |                                                                            |
# |  -f    |  file: Take regexes from a file.                                           |
# |  -o    |  Output the matched parts of a matching line.                              |
# +--------+----------------------------------------------------------------------------+
Comment

bash grep

# It can be done in two ways
# 1) Have "grep" read on from the standard input using a pipe
#    and search the input string. Then pipe the result to "wc" to count 
#    the number of occurences

$ line="This is where we select from a table."
# substr="select"

$ echo "$line" | grep "$substr" | wc -l

# 2) or pass a string to "grep" and search the string for a substring
#    pass the result to "wc" to count the number of occurence

$ grep "$substr" <<< "$line" | wc -l
Comment

grep i

With -i flag you can grep a substring with insensitive-case:
grep -i "substring_with_lower_or_upper_case"
Comment

PREVIOUS NEXT
Code Example
Shell :: what is uname -r linux 
Shell :: poetry requirements 
Shell :: change commit branch after push 
Shell :: command to start a system service 
Shell :: ssh mac 
Shell :: How to create and extract an archive or .tar file using linux commands 
Shell :: how to add ssh key to github 
Shell :: Err:9 http://ppa.launchpad.net/plushuang-tw/uget-stable/ubuntu focal Release 404 Not Found [IP: 91.189.95.85 80] 
Shell :: ubuntu navigate to directory in windows 
Shell :: flutter install in window 
Shell :: qgis linux 
Shell :: pdf file 30mb 
Shell :: docker build and run one command 
Shell :: install nvm mac 
Shell :: how to install tar.xz files on ubuntu 
Shell :: copy file from one directory to another in linux 
Shell :: packet10 
Shell :: daily bing ubuntu 
Shell :: Vim deleting all lines containing pattern 
Shell :: xargs ffmpeg multiples files 
Shell :: kazam or simplescreenrecord Recording the Black Screen in linux. 
Shell :: Get Android OS version of device connected via ADB 
Shell :: ng table angular 9 install 
Shell :: avalible ios simulators 
Shell :: Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package nano 
Shell :: add fold to path in linux 
Shell :: docker buildx build --platform linux/amd64,linux/arm64 -t username/application:latest --push . 
Shell :: updated git but still showing old version 
Shell :: bash print nth line 
Shell :: list of full path of file in text file ubuntu 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =