LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 05-17-2006, 03:15 PM   #1
rwartell
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:
03051982
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, 05:42 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
March 05 1982 was not a monday, but a friday.
But the line below will convert it correctly anyway:
Code:
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 06:08 PM.
 
  


Reply


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-18-2006 12:59 AM
I have a question about awk or sed sqp1982 Programming 9 03-28-2006 06:37 AM
Difficult sed/awk question 3saul Linux - Software 2 03-04-2006 03:49 AM
Simple question about sed or awk setianusa Programming 2 09-16-2005 04:57 PM
sed parsing question ncblues Linux - Newbie 5 01-03-2005 07:36 AM


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

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