We help IT Professionals succeed at work.
Get Started

Changing a date stamp in Unix/linux within a file

390 Views
Last Modified: 2012-05-10
Ok. I need to change ALL the date & hour stamps within a file. I have attached a sample file. I only want the date and times in column 1 (Jday) through column 7 (HR2) modified. I will then later modify the script in Perl. Unfortunately the Perl script requires a special module to be installed which I am having difficulty with. In Unix it is a simple thing to switch from UTC to local time but I need it to replace the current time stamp.  How would I do this? Again, the main date & time is column 1 (Jday) with the date and column (HR2). These need to be shifted back to local time HST which is always 10 hours earlier (no daylight savings time in Hawaii). So I could 1.  delete columns 2-5. 2. Read each row of data for columns Jday & HR2, then 3, change the date stamp & hour to local time.  For example, I look at three lines in the attached file,

12/03/2010 10 12 3 2 3 3 0.00 0.00 0.00 0.00 0.01 0.00 0.00 0.00 0.00 0.00 0.00
12/03/2010 10 12 3 5 3 6 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.02 0.00
12/03/2010 10 12 3 8 3 9 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

I would 1st delete the unwanted columns and it would look like this

12/03/2010  3 0.00 0.00 0.00 0.00 0.01 0.00 0.00 0.00 0.00 0.00 0.00
12/03/2010  6 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.02 0.00
12/03/2010  9 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

I would then change to time to look like this

12/02/2010  17 0.00 0.00 0.00 0.00 0.01 0.00 0.00 0.00 0.00 0.00 0.00
12/02/2010  20 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.02 0.00
12/02/2010  23 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

But this would be done for all lines of data in the file except the 1st line which names the columns
samplefile1.txt
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE