Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with a bash script

Status
Not open for further replies.

sco21

Technical User
May 20, 2002
67
GR
I want some help to make a script
this is my log file

2003-01-29 23:20:02 24138915 4841823
2003-01-29 23:25:02 23023245 4179976
2003-01-29 23:30:01 50114161 3065804
2003-01-29 23:35:01 24771375 3501016
2003-01-29 23:40:01 27893795 4199491
2003-01-29 23:45:01 26523593 3705775
2003-01-29 23:50:01 23440011 3372306
2003-01-29 23:55:01 23125174 4037042
2003-01-30 00:00:02 24366334 3715173
2003-01-30 00:05:01 26824279 3663193
2003-01-30 00:10:01 28317816 4285886
2003-01-30 00:15:01 28170460 6281458
2003-01-30 00:20:01 25076290 3312461
2003-01-30 00:25:01 27465629 3989601
........
........
........
How can I parse this file with a bash script
and give as arguments two dates

exm. script 2003-01-29 2003-01-30

and the output to give me only those dates from the file


THANKS
 
sco21 -

Have you considered using the grep command?

EXAMPLE -

grep 2003-01-29 logfile

You can also redirect the results to a new file...

grep 2003-01-29 logfile > newfile

If you wanted to add the second search results to the same file, use...

grep 2003-01-30 logfile >> newfile

">>" will append where ">" will overwrite.

Hope this helps!


Biker
Systems/Network Administrator
LiveFire Labs - Online UNIX and Linux Training
with Hands-on Lab Exercises
 
function date_grep() {
logfile="/var/log/logfile"
start=$1
end=$2

awk -v a=$start -v b=$end ' {
if ($1 == a || $1 == b) {
print
}
}' $logfile

return $?
}
 
THANKS FOR THE HELP FOR THIS FUNCTION
BUT IS THERE A WAY GETING THE RANGE OF TWO DATES

THANKS AGAIN.
 
Do you mean you would like the line numbers of the lines
constituting start and end patterns?
Please don't YELL, there is no need to.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top