Computing.Net > Forums > Unix > Help with grep

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Help with grep

Reply to Message Icon

Name: Darin Ambrose
Date: April 7, 2003 at 08:22:35 Pacific
OS: solaris
CPU/Ram: n/a
Comment:

I have posted about this in the past. But I am still having problems with it. I am tring to grep out the word UNCOVERED. When it finds this word I want it to also pull out the CLIENT. Can someone help me with this. I have put an example of the file below.

---Start File---
CLIENT: agentas1.agedwards.com

Drive Letter Backed Up By Class Notes
------ -----
C:\ An_agentas1_C
D:\ An_agentas1_D
system_State:\ UNCOVERED

CLIENT: agentas2.agedwards.com

Drive Letter Backed Up By Class Notes
------ -----
C:\ An_agentas2_C
D:\ An_agentas2_D

---End File---



Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: April 7, 2003 at 12:29:19 Pacific
Reply:

awk '\
BEGIN    {\
   latest="none"
   print "=============================="}
/CLIENT/ {\
   latest=$0}
/system_State/&&/UNCOVERED/ {\
   print latest
   print
   print "=============================="}
' myfile


0

Response Number 2
Name: dambrose13
Date: April 7, 2003 at 13:34:02 Pacific
Reply:

When I use the follwing script I am not getting any data

awk '\
BEGIN {\
latest="none"
print "=============================="}
/CLIENT/ {\
latest=$0}
/system_State/&&/UNCOVERED/ {\
print latest
print
print "=============================="}
' myfile


0

Response Number 3
Name: James Boothe
Date: April 7, 2003 at 14:53:14 Pacific
Reply:

That is pretty basic awk, and it works as expected on my HP.

Do you just get your shell prompt again, or does it hang until you cancel?

Make sure that you have replaced "myfile" with your actual filename to be processed.

Also, case is important. As per your sample data, I am looking for CLIENT and system_State and UNCOVERED.

If still no go, let me know exact symptoms and a copy/paste of some of your data.


0

Response Number 4
Name: Darin Ambrose
Date: April 8, 2003 at 05:31:56 Pacific
Reply:

I just get a shell prompt again. I am running on a solaris box if that makes any difference.


0

Response Number 5
Name: James Boothe
Date: April 8, 2003 at 06:55:13 Pacific
Reply:

I am assuming that the sample data that you posted was an actual copy/paste. If not, please copy/paste a relevant portion of your data file. Also, I would like to see the exact script that you are running. In regard to your reply that began "When I use the follwing script", I don't think that was the exact script because I suspect that your input file is not named "myfile". The exact script is quite important in debugging because a single space or something can be the problem. As another example, your last line could have been changed to something like:

' myfile > myfile.new

which of course would explain why you would be seeing nothing come to the screen.

And finally, just to get a simple success, what do you get when you run the folowing, after substituting the proper filename:

awk '/CLIENT/' myfile


0

Related Posts

See More



Response Number 6
Name: Darin Ambrose
Date: April 8, 2003 at 07:26:11 Pacific
Reply:

I took the out the /system_State/&&/ comment and the script worked successfully.

awk '\
BEGIN {\
latest="none"
print "=============================="}
/CLIENT/ {\
latest=$0}
/UNCOVERED/ {\
print latest
print
print "=============================="}
' myfile

Thank You for all your help.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Help with grep

need help with grep.... www.computing.net/answers/unix/need-help-with-grep/7366.html

problem with grep in a for loop www.computing.net/answers/unix/problem-with-grep-in-a-for-loop/3967.html

Help with grep/awk www.computing.net/answers/unix/help-with-grepawk/5577.html