Read full line from file

hello all

I'm writing a bash script and I need to read data from a file line by line
The number of words of each line is not known and I want to check if anywhere
in the line exists the substring www..That substring is a string by itself
or a substring of other strings.So what I tried so far is:

while read line;
do
	
	stringtocheck=($line)
	
	echo $stringtocheck
	if [[ "$stringtocheck" == *www.* ]]
	then
		//do things
	fi
	
done < './tempfile'  

But it only saves in the variable stringtocheck the first word of the line..
Instead I want the whole line.What shoud I do in this case?:confused:

try to put variable in double quotes -

stringtocheck=("$line")
echo "$stringtocheck"
1 Like

Try:

while read line
do
   if [ $(echo "${line}"|grep -c "www\..*") -ne 0 ]
	then
		//do things
	fi
	
done < './tempfile'
1 Like

@OP: Why the parentheses?

stringtocheck=$line

The intermediate variable is not necessary:

while read line;
do
  if [[ "$line" == *www.* ]]; then
    #do things
  fi
done < ./tempfile

or, more universally:

while read line;
do
  case $line in 
    *www.*) #do things
  esac
done < ./tempfile
1 Like
 
awk '/www/' filename
1 Like