Grep with Regular expression now working on file directories

Hello Everyone,

I have a file sam1 with the below content

SYSYSID;MANDT;/SIE/AD_Z0M_INDX;/SIE/AD_Z0M_KEY1

echo $Regex
\bSYSYSID\b|\bMANDT\b|\b/SIE/AD_Z0M_INDX\b|\b/SIE/AD_Z0M_KEY1\b

cat sam1 | grep -Eo $Regex

I expect the result as

SYSYSID
MANDT
/SIE/AD_Z0M_INDX
/SIE/AD_Z0M_KEY1

But the command is giving the result as

SYSYSID
MANDT

Any idea why? I tried to escape forward slash in "/SIE/AD_Z0M_INDX;/SIE/AD_Z0M_KEY1" but still no luck

Regards,
Sam

Try:

sed s,";","\n",g sam1 

hth

EDIT:

And to save it in the same file:

sed s,";","\n",g -i sam1 

Or, to save as another file:

sed s,";","\n",g sam1 > sam2 

With GNU grep, \b matches the empty string at the edge of a word. In the example the \b before the / is not at the edge of a word, because in the example SYSYSID;MANDT;/SIE/AD_Z0M_INDX;/SIE/AD_Z0M_KEY1 it is between a ; and a / . So try:

Regex='\bSYSYSID\b|\bMANDT\b|\B/SIE/AD_Z0M_INDX\b|\B/SIE/AD_Z0M_KEY1\b'

instead. Then

grep -Eo "$Regex" sam1

should produce:

SYSYSID
MANDT
/SIE/AD_Z0M_INDX
/SIE/AD_Z0M_KEY1

Hello ,

Sorry for the delay in response. I tried with \B but no luck..:frowning:
Still showing only the first 2 records. I am trying to check with a new file

Regards,
Sumith

What operating system and shell are you using? (As Scrutinizer said, the code he suggested with work with GNU grep . If you're not using a Linux system, there is a good chance that the grep you're using doesn't understand \b or \B .)