grep and wildcards


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep and wildcards
# 1  
Old 03-09-2005
grep and wildcards

Hi guys,

a small problem today, I'm grepping a log file containing lines like this below:
Code:
Mar 09 16:04:00 blabla
Mar 09 16:04:02 blabla
Mar 09 16:04:05 blabla
Mar 09 16:04:15 blabla
Mar 09 16:05:06 blabla
Mar 09 16:05:23 blabla
Mar 09 16:05:25 blabla
...

in this file I'm grepping expressions in "blabla" and I count how many off them are found per minute

like this for example:
Code:
grep my_expression my_log_file | grep "Mar 09 16:04" |wc -l

I want to wildcard "Mar 09 " so my grep is not dependant on the day anymore
(which can be "Thu 21 " or anything else)

Thanks for your help Smilie
# 2  
Old 03-09-2005
Code:
grep "[A-z]\{3,4\} [0-9]\{2\} 16:04"

...not dependent on the day, the month, or the day and month? your example using "Thu" is confusing.
# 3  
Old 03-10-2005
Quote:
Originally Posted by effigy
Code:
grep "[A-z]\{3,4\} [0-9]\{2\} 16:04"

...not dependent on the day, the month, or the day and month? your example using "Thu" is confusing.
thanks effigy, I tried something like that but I forgot to escape characters Smilie

Thu stands for Thursday, in fact there is three letters for each weekday at the beginning of the line Smilie

Edit: your hint works fine, thanks!

Last edited by Lomic; 03-10-2005 at 05:19 AM..
# 4  
Old 03-10-2005
now let's push a little further Smilie

how can I manage to have a loop which greps my expression for each minute of the day, between 0h00 and 23h59?

as I count the greps, each result of grep is a number

so at each step of the loop I wish to write it into a result_file
Code:
#!/bin/ksh
for hour/minute=0h00 to 23h59 do the following:
mygrep_for_hour/minute | wc -l >>my_result_file
next hour/minute

# 5  
Old 03-10-2005
Quote:
Thu stands for Thursday, in fact there is three letters for each weekday at the beginning of the line
i was thinking that, but the "Mar" threw me off Smilie

your idea sounds good, but it seems to be too much work. you may try running a sort on the file, use cut or awk to just get the date information, then loop through each line, comparing it to the previous. if equal, increment, if not, create a new one.
# 6  
Old 03-11-2005
No in fact I was wrong also lol, I thought it was day of the week "Mardi" for tuesday in french, but it is the month lol

so no problem anymore from this side

and for the moment I just count per hour in a quite silly maner but sufficient:
Code:
my_date=`date '+%Y-%m-%d'`
path="my_path/my.log"
file="my_result_"$my_date".log"
grep_expr=`date +'%b %d'`

echo "hourly grep on error_code_Z">>$file
grep "$grep_expr 00" $path | grep error_code_Z | wc -l>>$file
grep "$grep_expr 01" $path | grep error_code_Z | wc -l>>$file
grep "$grep_expr 02" $path | grep error_code_Z | wc -l>>$file
[...]
grep "$grep_expr 22" $path | grep error_code_Z | wc -l>>$file
grep "$grep_expr 23" $path | grep error_code_Z | wc -l>>$file

And I do it again for each error_code on I wish I want to make some stats

This way I obtain very nice curves under excel Smilie

Last edited by Lomic; 03-11-2005 at 07:34 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep multiple patterns that contain wildcards

job_count=`grep -e "The job called .* has finished | The job called .* is running" logfile.txt | wc -l` Any idea how to count those 2 patterns so i have a total count of the finished and running jobs from the log file? If i do either of the patterns its works okay but adding them together... (8 Replies)
Discussion started by: finn
8 Replies

2. UNIX for Dummies Questions & Answers

[Solved] Wildcards used in find, ls and grep commands

Platforms : Solaris 10 and RHEL 5.6 I always get double quotes , single quotes and asteriks mixed up for find, ls and grep commands. The below commands retrieve the correct results. But , unders stress , I get all these mixed up :mad: .So, i wanted to get a clear picture. Please check if... (7 Replies)
Discussion started by: John K
7 Replies

3. Shell Programming and Scripting

Grep wildcards

Hi all I want to search for number in file presented with wildcard as shown below. cat file.txt 1405 1623 1415 ....... ....... How to search for the number 141526 for example? If the number exist print "Number 141526 exist" if no, print "The number not exist" Thank you in advance. (3 Replies)
Discussion started by: vasil
3 Replies

4. Shell Programming and Scripting

Perl - grep issue in filenames with wildcards

Hi I have 2 directories t1 and t2 with some files in it. I have to see whether the files present in t1 is also there in t2 or not. Currently, both the directories contain the same files as shown below: $ABC.TXT def.txt Now, when I run the below script, it tells def.txt is found,... (5 Replies)
Discussion started by: guruprasadpr
5 Replies

5. UNIX for Advanced & Expert Users

Wildcards

These 2 websites do a GREAT job of explaining different types of wildcards. I learned about the categories of characters which I never knew about at all. GNU/Linux Command-Line Tools Guide - Wildcards GREP (1 Reply)
Discussion started by: cokedude
1 Replies

6. UNIX for Dummies Questions & Answers

wildcards NOT

Hi All Please excuse another straightforward question. When creating a tar archive from a directory I am attempting to use wildcards to eliminate certain filetypes (otherwise the archive gets too large). So I am looking for something along these lines. tar -cf archive.tar * <minus all *.rst... (5 Replies)
Discussion started by: C3000
5 Replies

7. UNIX for Dummies Questions & Answers

ls with wildcards

ok, I'm trying to write a script file that lists files with specific elements in the name into a txt file, it looks like this ls s*.dat > file_names.txt can't figure out whats wrong with that line, any ideas? thanks in advance (10 Replies)
Discussion started by: benu302000
10 Replies

8. UNIX for Dummies Questions & Answers

wildcards

when writing a shell script (bourne) and using a unix command like 'ls' is there anything special you need to do to use a wildcard (like *)? (3 Replies)
Discussion started by: benu302000
3 Replies

9. UNIX for Dummies Questions & Answers

Wildcards In UNIX

on my SCO UNIX wild cards are not displaying wanted result. Why like that . I think that i was not using proper command . what are there . how can i use the wildcards in UNIX. (7 Replies)
Discussion started by: smdakram
7 Replies

10. UNIX for Dummies Questions & Answers

Wildcards in VI

I'm trying to delete lines from a large text file using VI. Every line that I am wanting to delete start with 'S' - all others do not. (A list of users) I've tried using * but doesn't seem to like it...any ideas... Doesn't have to be VI - but I'm better with VI than sed/awk. (8 Replies)
Discussion started by: peter.herlihy
8 Replies
Login or Register to Ask a Question