If you have a use-case where you want to find out if a string exists in a file or not using a bash shell, then you can make use of the grep command.
grep "the-string-to-find" /file/path/
% bash-3.2$ grep 'Code2care' /Users/c2ctechtv/Desktop/data.txt
Code2care - Lines of code for a change!
% bash-3.2$ grep 'Code2care' /Users/c2ctechtv/Desktop/data.txt Code2care - Lines of code for a change!
If there is no match for the search, the command returns back to the bash shell.
Please note that the grep string searched using grep is case-sensitive by default. If you want to make it case insensitive make use of the -i flag along with it.
% bash-3.2$ grep 'welcome' /Users/c2ctechtv/Desktop/data.txt WELCOME
Facing issues? Have Questions? Post them here! I am happy to answer!
- Bash Hello World! Script Tutorial
- How to run bash command in background
- How to create new user account in Windows bash
- How to Compare Strings in Bash
- Bash: Allow Command to Fail without exiting Script
- Fix bash: script.sh: Permission denied Error
- Bash getopts Command Example
- How to fix bash ping command not found error
- How to add NewLine Character in Bash Script String
- How to Echo Bash Command to a File
- Bash Command to Find String in a File
- How to open new Terminal using Bash Command
- Bash How to Save Output of a Command to a Variable
- Download a SSL Certificate from a URL in Terminal
- Bash Command to Check IP Address
- Know Bash shell version command
- Bash Command To Check If File Exists
- How to run a Command in Bash Script
- How to Compare two Files in Bash Shell
- How to check if a variable is set in Bash Script or Not
- Convert String from uppercase to lowercase in Bash
- How to see Created Accessed Modified and Changed dates of a file using bash terminal command
- Bash Command To Get Current Time
- Bash command to List Files
- Fix: bash: syntax error near unexpected token
- Command to display epoch time Terminal - Linux
- Calculate Volume of Sphere - C-Program
- Download interrupted: Unknown Host dl-ssl.google.com Error Android SDK Manager - Android
- [Microsoft Teams] You're not on Teams yet, but you can set it up for your organization. - Teams
- How to call a SQL StoredProcedure from Hibernate - Java
- How to Set Homepage on Chrome - Chrome
- Error 404 Tomcat homepage http://localhost:8080/ not displayed - Tomcat
- JSON Syntax : JSON Tutorial - Json-Tutorial