How to print everything after a string match

Hi all,

I'm trying to do some work on the authorized_keys file to do a check if there's any information after the hash key.. At the end of the hash key's in the file, there can be an = or ==

Is there a way to check if anything exists after these equals and if so print it out or else print "Unknown Key"

Thanks,
Jaz

You could use a simple grep

$ if ! grep -v "=[^=]" authorized_keys; then
  echo "Found unknown key(s)"
fi

To process each key individually, perhaps a loop is better:

while read KEY; do
 [[ $KEY =~ =[^=] ]] || echo Unknown Key:
  echo $KEY
done < ~/.ssh/authorized_keys

Hi Scott,

I'm getting the below error when I try and run your loop suggestion.. Running this on Solaris so maybe the syntax is slightly different

ksh: syntax error: `=~' unexpected

Edit--

Have got the following to work, had to remove any extra = signs from the file first.. Just wonder if there's a more efficient way to do this though...

while read authsshkey
do
additioninfo=$(echo $authsshkey | cut -f2 -d"=")
if [[ "$additioninfo" == "" ]]
then
additioninfoout="no key"
else
additioninfoout=$additioninfo
fi
echo "$additioninfoout"
done < authorized_keys