Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.comDrive Letter Backed Up By Class Notes
------ -----
C:\ An_agentas1_C
D:\ An_agentas1_D
system_State:\ UNCOVEREDCLIENT: agentas2.agedwards.com
Drive Letter Backed Up By Class Notes
------ -----
C:\ An_agentas2_C
D:\ An_agentas2_D---End File---

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

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 "=============================="}
' myfile

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.

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

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 "=============================="}
' myfileThank You for all your help.

![]() |
![]() |
![]() |

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