Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

grep substring in bash

# 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 substring in shell

# You can do it in two ways
# 1) Let "grep" read on its standard input

echo "$line" | grep -o select

# 2) tell "grep" here is the string

grep select <<< "$line"
Comment

grep for substring

output=$(command)
[[ $output =~ (CpuIowait=[0-9][.][0-9]{2}) ]] && echo "${BASH_REMATCH[1]}"
Comment

PREVIOUS NEXT
Code Example
Shell :: install laravel installer on fish shell 
Shell :: compress folder raspberry 
Shell :: gdb value of type is more than max-value-size 
Shell :: Scryptenconder install 
Shell :: git checkout specific file types only 
Shell :: node installation error authenticated user is not valid 
Shell :: linux command check cpu type amd or not 
Shell :: cp verbose progress 
Shell :: are trying to install ruby-2.7.0 on heroku-20. remote: ! remote: ! Ruby ruby-2.7.0 is present on the following stacks: remote: ! remote: ! - heroku-18 
Shell :: Openzeppelin for Truffle install 
Shell :: launch bash script at startup linux 
Shell :: conda install cffi 
Shell :: bash read password 
Shell :: pip install softdelet 
Shell :: installing cdf 
Shell :: bash search and replace text in file 
Shell :: using screen in wsl 
Shell :: journalctl max log size 
Shell :: how to sort unsorted file and to write it to a new file bash 
Shell :: what is appmenu-gtk-module 
Shell :: how to install brew on jelastic 
Shell :: avd manger permission need root 
Shell :: install magento extension composer 
Shell :: create file cmd windows 
Shell :: terminal mkdir and cd 
Shell :: install latex editor 
Shell :: display folder color linux 
Shell :: get serial number for server using powreshell 
Shell :: dpkg: command not found 
Shell :: how to remove directory in linux 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =