grep -E drives me crazy

Hi there,

I'm new here. I registered my self today with this board because I hope to get some help before I'll become a slavering maniac.
I'm really desperate, since I'm trying for hours(really!) to let grep search a pattern that goes about 2 lines.
The pattern is as follows:
Handle 0x000xxxxxxx
Memory Module Information

I tried it as follows:
grep -i -E 'handle .*memory module information' -A 8

I also did that:
grep -i -E 'handle .*memory module information/m' -A 8

and that:
grep -i -E '^handle .*[\n]memory module information' -A 8

For the last 3 and a half hours I read so many pages about egrep, but nothing answers my question. It simply doesn't work.

Help me please (with sugar on top)

Best regards
darkelf

It's better to post your inputfile and the desired output instead of what you've done wrong.

Regards

Ahh, OK
The "inputfile" is the output of dmidecode. This output is fed into grep with a pipe.
e.g.

dmidecode | grep xxxxxxxxxxxxxxxxxxxxxxxx

The desired output is for instance:

Handle 0x0007, DMI type 6, 12 bytes
Memory Module Information
Socket Designation: A1
Bank Connections: 2
Current Speed: Unknown
Type: Other
Installed Size: 2048 MB (Single-bank Connection)
Enabled Size: 2048 MB (Single-bank Connection)
Error Status: OK

But I also would like to know, how newlines can be handled with grep (egrep).

Thank you.

Best regards
darkelf

try sed - grep is not easy spanning line boundaries:

dimdecode | \
sed -n '/Handle 0x000xxxxxxx/,/Memory Module Information/p'  > outputfile 

That was what I thought myself at first, but the problem is, that sed gives me also lines like that:

Handle 0x0025, DMI type 32, 11 bytes
System Boot Information
Status: No errors detected

and that is not what I want.
I want solely lines that start with a handel information like the one above followed by "Memory Module Information" and the next 8 lines that follow up.

But nevertheless, thanks for your answers so far.

Best regards
darkelf

OK, now i've found out, that

dmidecode | grep -i 'memory module information' -A 8 -B 1

gives the desired output, but the question remains: How to deal with newlines when grep is used.

try this
grep -i -E '(^handle|memory module information)' -A 8

Thank you very much, but that doesn't work either. It produces the same output as described above. That means it will show lines like:

  Handle 0x0025, DMI type 32, 11 bytes  System Boot Information  Status: No errors detected   

because it starts with "handle". I want only output if "handle" will be followed by "memory module information" in the next line. I've got some working code, but it's AWK and that's a language I don't know even a bit, so I'm looking for the same thing with grep or sed. This is it in awk:

 dmidecode | awk -v RS='\n\n' '/Memory Module Information/'  

Credits for the code to "ModestUser" from sidux-Forum. After all it's quite similar to

 grep -i 'memory module information' -A 8 -B 1 

which works pretty well, but doesn't answer my question. Best regards darkelf