Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-17-2006, 02:15 PM   #1
LQ Newbie
Registered: May 2006
Posts: 2

Rep: Reputation: 0
Sed or Awk question, looking for parsing help

Hi, I have the following problem. I need a script that will find in a .csv file dates of format
Mon Mar 05 18:34:38 1982
and change them to this format inside the file:
Can this be done with sed? Does it have the ability to find a something using regular expressions and then modify it rather than replacing it? Or must this be done in awk? Any answers would be awesome. Thanks a lot.
Old 05-17-2006, 04:42 PM   #2
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
March 05 1982 was not a monday, but a friday.
But the line below will convert it correctly anyway:
date -d 'Mon Mar 05 18:34:38 1982' +%m%d%Y
It should be possible with sed, but it would be a tedious task. Not recommended for sure (in this case, handling date conversion).

If the date fields are always at the start of the lines, you don't even need to search for them: just run "date" on the first 24 chars. If that's invalid, "date" will return non-zero exit code.

If the dates are in certain field number(s) of the csv file, I'd use awk. Have a look at the strftime() function of awk for conversion (this will be similar to the "date" example above).

If the dates can be anywhere in the lines of the CSV file, use grep to find the date strings, and convert them with "date". (see above)

Last edited by Hko; 05-17-2006 at 05:08 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sed or Awk question, looking for parsing help rwartell Linux - Software 2 05-17-2006 11:59 PM
I have a question about awk or sed sqp1982 Programming 9 03-28-2006 05:37 AM
Difficult sed/awk question 3saul Linux - Software 2 03-04-2006 02:49 AM
Simple question about sed or awk setianusa Programming 2 09-16-2005 03:57 PM
sed parsing question ncblues Linux - Newbie 5 01-03-2005 06:36 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:50 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration