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

Remove the date from a text file

Status
Not open for further replies.

Dominal

Technical User
Mar 2, 2003
14
HK
Hi!

I have a text file with many lines and each line contains today's date in the format cyyddd (century,year,day of the year) in different position. How to chop all the date using shell script (sh/csh)?

Thanks!
 
One way is sed:

sed 's/003063//g' data.file

Regards,

Ed
 
Or get today as a variable :
#!/bin/ksh
das=`date +%Y%m%d`
sed 's/'$das'//g' testfile > newfile

HTH Dickie Bird (:)-)))
 
Thanks Olded and Dickiebird!

However, the +%Y%m%d only shows the date in the format 20030305 instead of 003064(0->century, 03->year, 064->day 64 of year 2003). How can we transform into the day of the year?
 
Use %j ( do a lookup in the manual for date)
and use cut to trim the returned string:
das=`date +%Y%m%j|cut -c2-9`

HTH Dickie Bird (:)-)))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top