Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

find a substring from a string

// CPP program to demonstrate working of string
// find to search a string
#include <iostream>
#include <string>
  
using namespace std;
  
int main()
{
    string str = "geeksforgeeks a computer science";
    string str1 = "geeks";
  
    // Find first occurrence of "geeks"
    size_t found = str.find(str1);
    if (found != string::npos)
        cout << "First occurrence is " << found << endl;
  
    // Find next occurrence of "geeks". Note here we pass
    // "geeks" as C style string.
    char arr[] = "geeks";
    found = str.find(arr, found+1);
    if (found != string::npos)
        cout << "Next occurrence is " << found << endl;
  
    return 0;
}
Comment

search for substring

# 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

PREVIOUS NEXT
Code Example
Shell :: Concatenating Strings in Bash 
Shell :: shell search history 
Shell :: which command is used to create a new git repository 
Shell :: scp send file to remote 
Shell :: git merging to branch from branch 
Shell :: how to download fl studio on linux 
Shell :: Cocoapods not found in android studio but flutter run works 
Shell :: datadog without agent 
Shell :: composer download 
Shell :: add gist file to dev.to 
Shell :: packet tracer 2.7.1 Full Config BC-3 Router 
Shell :: cordova could not install from "android" as it does not contain a package.json file. 
Shell :: npm install electron-reload 
Shell :: connect to remote redis over tls 
Shell :: unity install server cache 
Shell :: create vite app 
Shell :: copy content from one files to another in linux shell script 
Shell :: create aws ec2 launch template 
Shell :: grep string in file 
Shell :: Warning: Broken symlinks were found. Remove them with `brew cleanup`: 
Shell :: consolidated version yarn.lock 
Shell :: linux copy move 
Shell :: Setting File Permission Allow Webserver di linux 
Shell :: git change autor of all comits 
Shell :: ./RsaCtfTool.py: command not found kali linux 
Shell :: c pipe 2 arguments 
Shell :: installation testing 
Shell :: install graphene federation 
Shell :: libcblas-dev 
Shell :: linux delete all files except extension 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =