Hello,
I want to check if some word exist or not on some file
By Example :
word is : nixcraft
file called : /root/shell.txt
and i want to check if nixcraft word exist on /root/shell.txt file with if statement or another tool
Any Ideas
Hello,
I want to check if some word exist or not on some file
By Example :
word is : nixcraft
file called : /root/shell.txt
and i want to check if nixcraft word exist on /root/shell.txt file with if statement or another tool
Any Ideas
grep -i 'nixcraft' /root/shell.txt
i want it in if statement syntax
if [....]; then
else
fi
thanks for your reply
#!/bin/sh
file=/root/shell.txt
word="nixcraft"
if [ -f "$file" ]; then
echo "File $file does not exist."
exit 1
fi
cmd=$(grep -ci "$word" $file)
if [ "$cmd" != "0" ]; then
echo "Word exists"
else
echo "Word does not exist."
fi
Thank you very mush
This is good idea
thanks, works perfectly and exactley what I was looking for.