grep -E drives me crazy


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep -E drives me crazy
# 1  
Old 02-17-2009
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


Last edited by darkelf; 02-17-2009 at 04:44 PM.. Reason: Typo
# 2  
Old 02-17-2009
It's better to post your inputfile and the desired output instead of what you've done wrong.

Regards
# 3  
Old 02-17-2009
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
# 4  
Old 02-17-2009
try sed - grep is not easy spanning line boundaries:
Code:
dimdecode | \
sed -n '/Handle 0x000xxxxxxx/,/Memory Module Information/p'  > outputfile

# 5  
Old 02-17-2009
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.

Last edited by darkelf; 02-17-2009 at 05:57 PM.. Reason: possible solution
# 6  
Old 02-18-2009
try this
grep -i -E '(^handle|memory module information)' -A 8
# 7  
Old 02-18-2009
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:
Code:
  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:
Code:
 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
Code:
 grep -i 'memory module information' -A 8 -B 1

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

Last edited by darkelf; 02-18-2009 at 03:42 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Crazy Syntax

Hello All, was looking at a script wrote by someone and when I try and run it in ksh it gives me an error. Could ksh version be a problem or is there something wrong that I'm missing, when I run it from the command line it works. Thanks! results=`sudo -u admin ssh... (1 Reply)
Discussion started by: akechnie
1 Replies

2. Shell Programming and Scripting

Unary Operator Expected ---drives me crazy

Hi i get this code in my shell script for shinken : kind_fan() { oid_fan_count=".1.3.6.1.4.1.1211.1.15.4.5.0" SNMPGETCMD="${SNMPGET} -Ovq ${oid_fan_count}" fancount=`${SNMPGETCMD}` verbose "command=${SNMPGETCMD}" "result=${fancount}" i=1 ... (3 Replies)
Discussion started by: martin24
3 Replies

3. What is on Your Mind?

Here's To The Crazy One

Please excuse my indulgence. Thank you MG Siegler and Steve Jurvetson. But most importantly, thank you Steve Jobs. 8rwsuXHA7RA The world has lost a genius. (1 Reply)
Discussion started by: Scott
1 Replies

4. Shell Programming and Scripting

Finger has gone crazy

Two things : On the first place i am really desperate, on the second i am about to throw my laptop away to the recycle bin in a while. Ok now that i expressed my feeling let me describe you this mad situation. Code: print $1; ("finger -m " $1 "| head -1") | getline userinfo print... (6 Replies)
Discussion started by: beatblaster666
6 Replies

5. What is on Your Mind?

crazy dreams..

well, Wine is simply amazing.. I love it. the filesystems are great too -- never having to defragment, and not slowing down in time. I love the power of BASH. iptables.. but.. I had a vision. a crazy dream. what if, we could develop an installation system for Linux.. working pretty much... (3 Replies)
Discussion started by: ialoq
3 Replies

6. Shell Programming and Scripting

ftp going crazy

Dear Friends, I am having a crazy issue with ftp. I am doing 'mput' of 4 files (z1, z2, z3, z4) as below. But ftp transfers only every alternative file !! - ie; If I do mput z* for above, it sends only z1 and z3. Note that all the files are same and I tried this for several dummy files. All... (3 Replies)
Discussion started by: yoursdivu
3 Replies

7. Shell Programming and Scripting

how floppy disks, CDs and flash drives (pen drives) are accessed in UNIX

hi how floppy disks, CDs and flash drives (pen drives) are accessed in UNIX? thanks (0 Replies)
Discussion started by: nokia1100
0 Replies

8. Shell Programming and Scripting

going crazy with test???

oK, i know for sure that code = Y and var = N but no matter what this always prints ignore, never valid??????? if test "$code"="$var" ... (2 Replies)
Discussion started by: mich_elle00
2 Replies

9. Shell Programming and Scripting

M4 quoting drives me crazy

Hi, I have trouble with quotations of the M4 preprocessor. I want to write a basic makro that removes all spaces and newlines at the end and at the beginning of a string. I tried this: define(`TRIM_END', `patsubst(`$1', `\(\\n\| \)*$', `')') define(`TRIM', `patsubst(`TRIM_END(`$1')',... (0 Replies)
Discussion started by: hindman
0 Replies

10. UNIX for Dummies Questions & Answers

Oh no!! crazy script

Hi Could be stupid, but I can figure out... I have a script that downloads a file from a http server ( virus definitions file ). The thing is that when I run it from the console (bash) works fine, but when I put it in the root's cron it doesn't, and it generates a core file. example: ... (8 Replies)
Discussion started by: piltrafa
8 Replies
Login or Register to Ask a Question