Ad

While Command In Bash "if There's A $string In File.txt... Do..."

- 1 answer

Need help with the while command. I want to run a command if there's a $sitename in playlist.txt

Here's my bash:

   cat playlist.txt | grep -e "$sitename" |  sed -e "s/^.*\(http:.*"$sitename".*flv\).*$/\1/g" | sort | uniq > checklist.txt
cat checklist.txt

while [ " While can find $sitename in checklist.txt" ]; do
                qa
         done

that's what i have tried already

while [ -n "$echopl" ]; do
                    qa
             done

while [ 'grep -q $string checklist.txt >/dev/null' ]; do
                qa
         done

while [  "grep -q "$string" checklist.txt" ]; do
                qa2
         done
while grep -q "$string" checklist.txt; do
    qa
done

while grep -q '$string' checklist.txt; do
    qa
done


if grep -q "$string" checklist.txt ; then
  qa
fi

Temporarily I put many if commands :(

ifmorelinks ifmorelinks ifmorelinks ifmorelinks ifmorelinks

Ad

Answer

if grep "$string" checklist.txt >/dev/null 2>&1 ; then
  qa
fi
Ad
source: stackoverflow.com
Ad