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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timestamped File

Status
Not open for further replies.

SpongeBob1

Programmer
Mar 1, 2002
49
US
Hi,

I was just wondering if anybody knows how to write a C Shell script which can seperate a timestamped file into a number of seperate files, based on the timestamp?

Thanks.
 
Please expand on your requirements - post a sample of the file too !
:) Dickie Bird
db@dickiebird.freeserve.co.uk
 
Hi,
if the file contains a timestamp on each line and you want to break that file into separate files the easiest way is to build a list of UNIQ dates in the file and then grep each date out of the file into separate files...

like ( assuming the time stamp is the first entry on the line. )

foreach mydate ( `cut -d' ' -f1 myfile | sort | uniq` )
egrep "^$mydate" myfile >! file.$mydate
end

now this doesn't work if the time stamp has spaces in it like

Jan 3 1995

because the above would put all the lines with Jan into a file. If you change the cut to

cut -d' ' -f1-3

the grep will think Jan 3 and 1995 are 3 separate dates and grep for them all. It is better if the dates are like..... 19950103

because those will Grep and sort much easier.

Hope this helps.
---

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top