2
I'm sure most of us know that when we want that some regex matches with a string at the begin of the line we must use "^" ...
But, I'm trying to understand what really means "empty string at the begin of the line"
I know that echo "Hello World" | grep ^H it matches
So please take a look the output of these commands:
[sergio@localhost ~]$ dd if=/dev/zero of=/tmp/texto count=1 bs=1 2>/dev/null
[sergio@localhost ~]$ od -ta /tmp/texto
0000000 nul
0000001
So far everything as expected, so:
[sergio@localhost ~]$ echo "Hello" >> /tmp/texto
[sergio@localhost ~]$ grep -a "^Hello" /tmp/texto
Well the first thing I must confess didn't expected, before of Hello there are a null character, so why is it not matching?
OK, let's use grep in perl style:
[sergio@localhost ~]$ grep -a -P "\x00Hello" /tmp/texto
Hello
OK, It matches
But what I don't understand (perhap I have some misconcept) why grep -a "^Hello" does not match...
Could you help me?
thanks in advance!
1Sorry, I was mistaking null with empty string!! – sebelk – 2013-09-04T12:44:57.870