1

I have a very simple sequence of bash commands:

echo "output 3:"
echo "abc shalom" >|F1
echo " abc shalom 4" >> F1
echo "abc shalom12" >> F1
echo "abc shalom123 shalom6" >> F1
echo "abcshalom22 456 shalom" >> F1
egrep "(^|[ ]*)[^ ]+[ ]+shalom($|..[ ])" F1

the output is:

abc shalom
abcshalom22 456 shalom

I can't understand how this simple regex works, I understand that the pipeline is "or", but I dont understand how do I get those two lines...

Could someone please explain me step by step what happened in this short regex?

fedorqui
  • 275,237
  • 103
  • 548
  • 598
nick shmick
  • 905
  • 1
  • 9
  • 25
  • Not to get off track but it's called a "pipe" not a pipeline but it is a line called a pipe so does anyone call it a pipeline? – Rob Jan 31 '15 at 14:34

1 Answers1

1

Let's see:

egrep "(^|[ ]*)[^ ]+[ ]+shalom($|..[ ])" F1

| indicates to match either one thing or another. Hence, aa|bb means: match either aa or bb.

Saying ^|[ ]* you are using a regex to match either the beginning of the line (represented by ^) or a sequence of zero or more spaces (represented by [ ]*).

fedorqui
  • 275,237
  • 103
  • 548
  • 598