How to use a string as a delimiter shell script

Posted by Dan on Stack Overflow See other posts from Stack Overflow or by Dan
Published on 2012-06-07T16:38:07Z Indexed on 2012/06/07 16:40 UTC
Read the original article Hit count: 227

Filed under:
|

I am reading a line and am using regex to match it in my script. (/bin/bash)

echo $line | grep -E '[Ss][Uu][Bb][Jj][Ee][Cc][Tt]: [Hh][Ee][Ll][Pp]' > /dev/null 2>&1
if [[ $? = "0" && -z $subject ]]; then
    subject=`echo $line | cut -d: -f2` > /dev/null
    echo "Was able to grab a SUBJECT $line and the actual subject is -> $subject" >> $logfile

fi

now my problem is that i use the colon as the delimiter. but sometimes the email will have multiple colons in the subject and so I am not able to grab the whole subject because of that. I am looking for a way to grab everything after the colon following subject. even is there is a way to loop through and check for a colon or what. maybe cut allows you to cut with a string as delimiter? Not sure...any ideas?

Thanks!

© Stack Overflow or respective owner

Related posts about shell

Related posts about cut