pattern matching

Can someone tell me whether is there a way to test ABC is starting in AB CDEF and then drop AB C and retain DEF alone.

Thanks in advance!

Is this what you want:

echo 'ab cdef' | sed 's/ab[ ]*c//'

Similar kind of... I just want to generalize it for any kind of strings or numbers. Could you shed more light on this. Thank you very much!

Any kind of string in between also means 'abccdef'.

In this case what output do you expect?

Thanks, shell life!
VAR1="AB CDEF"
VAR2="ABC"

I just want to know whether VAR1 is starting with VAR2. There could be spaces in between VAR1 characters like i mentioned in the above example. Then i just need to drop "AB C" from VAR1 and retain remaining stuffs. Any suggestions how this could be done.
Thanks!

Here VAR3 holds the "remaining stuffs" from VAR1 if it matches VAR2.

VAR1="AB CDEF"
VAR2="ABC"
VAR3=$(echo "$VAR1" | sed -n "s/ //g; s/$VAR2//p")

so you need to check for var1 in var2 with any number of spaces randomly inserted?

var1="abc"
var2="a  b c def"
pattern=$(echo $var1 |sed 's/\(.\)/\1 */g')
echo $var2|sed "s/^$pattern//"

Using sed to add an "And any number of spaces" phrase after each character in var1 in order to create a pattern we can subsequently use to find var1 in var2 with any amount of spaces randomly inserted.

Thank you very much, Michael!

---------- Post updated at 03:00 AM ---------- Previous update was at 02:57 AM ----------

Thank you very much, Skrynesaver.