LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 08-06-2012, 10:04 AM   #1
jscottcc
LQ Newbie
 
Registered: Aug 2012
Posts: 11

Rep: Reputation: 0
How to change strings within a field


So I'm working as an IT intern this summer and I'm a bit over my head with some of the coding stuff, any help would be greatly appreciated.

I have a file of dates and times which is delimited by spaces, and looks something like this:

Code:
Jul 22 2012 11:43PM
Jul 20 2012 11:22AM
Jul 19 2012 5:06PM
And ultimately it will be cast to an array and compared with another file which has matching times and dates, however those same dates are formatted like so:

Code:
7 22 2012 11:43PM
7 20 2012 11:22AM
7 19 2012 5:06PM
I believe this can be done using awk, and I tried tweaking some code I found around the internet for similar purposes.

I'm not worried about how to code it to go through and check which month, then find the proper number, etc. I know I can do that with a long and probably messy if-else statement. But how do I actually convert the string into the number?
 
Old 08-06-2012, 10:11 AM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Have a look at those two places.
http://stackoverflow.com/questions/1...a-month-string
http://stackoverflow.com/questions/1...-integer-shell
 
  


Reply



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
Handling field width in multibyte strings with printf formats? johan162 Programming 2 03-15-2012 01:27 AM
Shadow 'last change' field s0n|k Linux - Newbie 1 02-25-2006 11:45 AM
How to overwrite/change characters in the same field with C. slzckboy Programming 6 05-23-2005 05:07 PM
how to change rpm's requirements field polrus Linux - Software 1 05-10-2005 11:35 AM
GECOS field name change kadissie Linux - General 1 11-29-2004 06:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:17 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
Open Source Consulting | Domain Registration