Assuming your file names don't contain newline characters, this will remove lines containing just ASDF from all files in the current directory, unless the file consists of a single line containing just ASDF. If your sed doesn't have the -i option, output to a temporary file and move it in place afterwards.
grep -l ASDF -- * | while IFS= read -r filename; do
if ! echo 'ASDF' | cmp -s - "$filename"; then
sed -i -e '/^ASDF$/d' -- "$filename"
fi
done
Here's another approach, which removes the ASDF lines, and only overwrites the original file if the new file is neither empty nor identical to the original.
tmpfile=$(mktemp -p "$(dirname -- "$filename")")
sed '/^ASDF$/' <"$filename" >"$tmpfile"
if [ -s "$tmpfile" ] && ! cmp -s -- "$filename" "$filename"; then
mv -f -- "$tmpfile" "$filename"
else
rm -- "$tmpfile"
fi
hello ASDF? Or a file that contains multipleASDFlines but nothing else? – Gilles Aug 28 '11 at 17:40