Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8845233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:41:17+00:00 2026-06-14T11:41:17+00:00

I have a file with records having timestamp fields that include GMT offset. I

  • 0

I have a file with records having timestamp fields that include GMT offset. I want to use the sed command to replace the value on the record to a regular timestamp (without GMT offset).

For example:

`$date -d '2012/11/01 00:50:22 -0800' '+%Y-%m-%d %H:%M:%S'`

returns this value which is what I am looking to do:

2012-11-01 01:50:22

Except I want to perform that operation on every line of this file and apply the date command to the timestamp value. Here is a sample record:

"SB","6GV96644X48128125","","","","T0006",2012/10/03 13:08:43 -0700,"NJ"

Here is my code:

head -1 myfile | sed 's/,[0-9: /\-]\{25\},/,'"`date -d \1 '+%Y-%m-%d %H:%M:%S'`"',/

which doesn’t work: it just ignores \1 and replaces the matched pattern with today’s date:

"SB","6GV96644X48128125","","","","T0006",2012-11-14 01:00:00,"NJ"

I hoped that \1 would result in the matched patterns be passed to the date function and return a regular timestamp value (as in the example I provided above showing how the date functions applies the GMT offset and returns a regular stimestamp string) and would replace the old value on the record.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:41:19+00:00Added an answer on June 14, 2026 at 11:41 am

    I would use awk instead. For example:

    awk '{cmd="date -d \""$7"\" \"+%Y-%m-%d %H:%M:%S\"";
        cmd | getline k; $7=k; print}' FS=, OFS=, myFile
    

    This will replace the 7th field with the results of running the date command on the original contents of the 7th field.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file of string records where one of the fields - delimited
I have a large .txt file of records that I need to convert into
I have a CSV file with set of records on it. While I use
I have a large disk file (around 8 GB) containing several million records that
I basically have a program that filters records from one excel file to another
I have a page that inserts records into a table. what i am having
I am a beginner and I have a file having variable sized records; there
I have a file containing records delimited by the pattern /#matchee/. These records are
I have a text file containing a number of records. Each record is stored
I have long HTTP request ( generating large Excel file - about 60K records

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.