Help a beginner with GREP!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help a beginner with GREP!
# 1  
Old 04-27-2012
Help a beginner with GREP!

Hi,

I am stll new to this shell stuff... but trying to teach myself (i'm the only one in my country's office that does this...). What I need to do is search for any line in our logs that contain both "USRLOGIN" and also the number "6141".

This is fine... but it also brings up lines where these patterns are part of a bigger string... e.g. 6141 could be inside "84785614149" or USRLOGIN inside "USRLOGINAS". How would I define that it the patterns provide should *not* be part of a bigger string?

This is what I kind of imagined:

Code:
cd xx/logs/2012/ 
for i in 0{1..4}; do zgrep "USRLOGIN" /$i/*/ecm1.* | zgrep "6141"

This also brings two other issues. The logs are kept in a directory by year/month/day. I grep from inside the year, and define the month as $i, but then can I just use the asterisk wildcard to define the day and actual file (/$i/*/ecm1.*).

Lastly, if I want to append a second grep on for 6141 (assuming this is the right way to do it), do I append it on the end as zgrep or grep? The files are .gz, but should the grep to the right of the pipe (|) be zgrep or grep.

Hope you can help a beginner! I searched lots but got confused. Please try not to get tooooo technical Smilie

Cheers,

Alex
# 2  
Old 04-27-2012
use -w with your grep
Code:
 
zgrep -w

---------- Post updated at 03:48 PM ---------- Previous update was at 03:47 PM ----------

man zgrep

Code:
-w, --word-regexp
      Select only those  lines containing  matches  that  form  whole
      words.   The  test is that the matching substring must either be
      at the beginning of the line, or preceded  by  a non-word  con-
      stituent character.  Similarly, it must be either at the end of
      the line or followed by a non-word constituent character.  Word-
      constituent  characters are letters, digits, and the underscore.

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Red Hat

Help me please i am beginner

i have windows 8 host on Dell Laptop vmware 9 redhat 7.2 iso downloaded through redhat official site after installation on vm it only boots into text dont show graphics Please guide:( (1 Reply)
Discussion started by: hananabbas
1 Replies

2. UNIX for Dummies Questions & Answers

awk Help - Beginner

Hi, I think I need to use AWK - however I have no experience of it. Can someone help please? I have a file like this but with many more records - it is fixed width THIS15021X 799999 XX 00000099999 00008888888 XX 15022013 THISQ15021X 999999 XX 00000099999... (7 Replies)
Discussion started by: mcclunyboy
7 Replies

3. Shell Programming and Scripting

Beginner looking for help

Hello, I am trying to write a script that reads names from a file called input, removes names if they have the same letter next to each other and prints the others. e.g. Colin & John would be printed Garry & Lynn would be removed My thinking is that I read in each name and... (3 Replies)
Discussion started by: colinireland
3 Replies

4. UNIX for Dummies Questions & Answers

Beginner - What Should I Do First?

Hi people.... I have just started to learn unix.I want to know which version of Unix to install plus how to install it.I need to practise and make myself aware of how unix works.My thread is from an educational point of view.Also please feel free to give your suggestions as I am... (3 Replies)
Discussion started by: amit.kanade1983
3 Replies

5. Shell Programming and Scripting

Beginner Help

I need to write a script to test a nsort c program. I have written 8 .txt files with different cases. Also 8 .txt files with expected outcome. The shell I have written always "test pass" for the first case but always "fail" for the rest... Here is a portion of my code (as I still don't know how to... (5 Replies)
Discussion started by: thibodeau
5 Replies

6. UNIX for Dummies Questions & Answers

Beginner Help

hi guys, i have a DEl xps laptop cor 2 duo 2.2 i have vista installed on it i want to install a dual Boot UNIX on it.. can some one guide me ...cause i m tottaly new to UNIX i want to install unix on that laptop along with Vista.... thx any help would be deeply appreciated (sorry if i... (5 Replies)
Discussion started by: Farhan082
5 Replies

7. Shell Programming and Scripting

Beginner for Perl

Hi, I'm new in Perl. Can anyone recommend me any e-book which is good for beginners? Thanks. (3 Replies)
Discussion started by: raul15791
3 Replies

8. Programming

Beginner C

Anyone know where I can get started in C++ programming in unix? Any good free tutorials or websites to start at? I am okay in unix scripting but have never done c programming of any sort... What are the main advantages of using C++ ? (2 Replies)
Discussion started by: frustrated1
2 Replies

9. Shell Programming and Scripting

Please help. I am a beginner.

Alrigt, I need to write a shell script where it counts the number of folders and files and dispays "My home directory has 'x' files and 'y' directories." So, I was thinking of doing this. set x = `ls | wc` so, if I have 8 files and folders in my home directory, x is not 8. now, I was... (1 Reply)
Discussion started by: Lykathea Aflame
1 Replies
Login or Register to Ask a Question