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

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}'
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.