0

Hi

I am a newbie in shell scripting ... I can honestly say, I am just learning to write shell scripts .. But, I am in need for a script which does the following:

There is a file which has the contents as follows:

date time contents
date time contents

I have to read the file for a given date / time range say an hour every day and count the number of lines within that hour ....

Can somebosy out here pelae help me. Thanks

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by chris5126
0

I would look at awk and grep and wc.

Awk will print out columns of a file so try.

cat filename | awk '{print $1}'

You can change $1 to any number to print out the different columns.

You can use grep to find dates or times within a certain range e.g

grep "date" filename

Then once you have greped the correct lines from the file you can pipe this output to wc.

file | wc

This will display three figures your interested in the first column it tells you the number of lines in a file.

An example kinda looking at what you want to do would be: (please note not exact code)

FILE=filename
RANGE=date you are looking for

grep $RANGE $FILE | wc | awk '{print $1}'
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.