Answers for "bash file contains string"

4

bash string contains

#!/bin/bash

STR='GNU/Linux is an operating system'
SUB='Linux'
if [[ "$STR" == *"$SUB"* ]]; then
  echo "It's there."
fi
Posted by: Guest on June-29-2020
0

bash if file contains string

if grep -q SomeString "$File"; then
  Some Actions # SomeString was found
fi
Posted by: Guest on March-24-2020
1

bash check if string in file

Just use grep with flags 'F' (fixed string), 'x' (exact match) and 'q'
(quiet output) in order to check if a word string is in a file
if grep -Fxq "string" file.txt; then #do some code...#; fi
Posted by: Guest on November-11-2020

Code answers related to "bash file contains string"

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language