Visit Our UNIX and Linux User Community


change date format - 2009-10-30 -> today


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting change date format - 2009-10-30 -> today
# 1  
Old 10-30-2009
change date format - 2009-10-30 -> today

Hello, new to this forum, I'm running Ubuntu 9.10 i386. I've search and found some relevant info on how to do this but I haven't been able to figure it all out. I'm trying to output my mythtv pvr's upcoming schedule but I'd like to change the dates from 2009-10-30 -> today, 2009-10-31 -> tomorrow and 2009-11-01 -> sunday. Having todays date come up as 'today' isn't too important, resorting to day of the week is better than nothing.
Code:
myth_upcoming_recordings.pl --plain_text --text_format '%Y-%m-%d - %h:%i %A - %T - %S (%cN)\n' --heading ""
2009-10-30 - 04:00 PM - Ghost Hunters - Nightmare Noises (OLCC)
2009-10-30 - 05:30 PM - The Simpsons - Treehouse of Horror XI (KCPQ)
2009-10-30 - 06:00 PM - The Simpsons - Treehouse of Horror XII (KCPQ)
2009-10-30 - 09:00 PM - The Simpsons - Treehouse of Horror XIX (COMEDCP)
2009-10-31 - 12:00 AM - Project Runway - A Fashionable New Beginning (SLICE)

the closest I've gotten is pretty bad
Code:
TEXT=`myth_upcoming_recordings.pl --plain_text --text_format '%Y-%m-%d - %h:%i %A - %T - %S (%cN)\n' --heading ""`
DATE=`echo "$TEXT"|awk -F'% ' {'print $1'}`
SHOW=`echo "$TEXT"|awk -F'% ' {'print $2 $3 $4 $5 $6'}`
DAY=`date -d $DATE +%a`
awk -v DAY="$DAY" SHOW="$SHOW"'{print DAY SHOW}'

there is a lot of configuration with the myth_upcoming_recordings.pl script if it makes it easier
Code:
--text_format

    %T   = Title (show name)
    %S   = Subtitle (episode name)
    %R   = Description
    %C   = Category
    %U   = RecGroup
    %hn  = Hostname of the machine where the file resides
    %c   = Channel:  MythTV chanid
    %cn  = Channel:  channum
    %cc  = Channel:  callsign
    %cN  = Channel:  channel name
    %y   = Recording start time:  year, 2 digits
    %Y   = Recording start time:  year, 4 digits
    %n   = Recording start time:  month
    %m   = Recording start time:  month, leading zero
    %j   = Recording start time:  day of month
    %d   = Recording start time:  day of month, leading zero
    %g   = Recording start time:  12-hour hour
    %G   = Recording start time:  24-hour hour
    %h   = Recording start time:  12-hour hour, with leading zero
    %H   = Recording start time:  24-hour hour, with leading zero
    %i   = Recording start time:  minutes
    %s   = Recording start time:  seconds
    %a   = Recording start time:  am/pm
    %A   = Recording start time:  AM/PM
    %ey  = Recording end time:  year, 2 digits
    %eY  = Recording end time:  year, 4 digits
    %en  = Recording end time:  month
    %em  = Recording end time:  month, leading zero
    %ej  = Recording end time:  day of month
    %ed  = Recording end time:  day of month, leading zero
    %eg  = Recording end time:  12-hour hour
    %eG  = Recording end time:  24-hour hour
    %eh  = Recording end time:  12-hour hour, with leading zero
    %eH  = Recording end time:  24-hour hour, with leading zero
    %ei  = Recording end time:  minutes
    %es  = Recording end time:  seconds
    %ea  = Recording end time:  am/pm
    %eA  = Recording end time:  AM/PM
    %py  = Program start time:  year, 2 digits
    %pY  = Program start time:  year, 4 digits
    %pn  = Program start time:  month
    %pm  = Program start time:  month, leading zero
    %pj  = Program start time:  day of month
    %pd  = Program start time:  day of month, leading zero
    %pg  = Program start time:  12-hour hour
    %pG  = Program start time:  24-hour hour
    %ph  = Program start time:  12-hour hour, with leading zero
    %pH  = Program start time:  24-hour hour, with leading zero
    %pi  = Program start time:  minutes
    %ps  = Program start time:  seconds
    %pa  = Program start time:  am/pm
    %pA  = Program start time:  AM/PM
    %pey = Program end time:  year, 2 digits
    %peY = Program end time:  year, 4 digits
    %pen = Program end time:  month
    %pem = Program end time:  month, leading zero
    %pej = Program end time:  day of month
    %ped = Program end time:  day of month, leading zero
    %peg = Program end time:  12-hour hour
    %peG = Program end time:  24-hour hour
    %peh = Program end time:  12-hour hour, with leading zero
    %peH = Program end time:  24-hour hour, with leading zero
    %pei = Program end time:  minutes
    %pes = Program end time:  seconds
    %pea = Program end time:  am/pm
    %peA = Program end time:  AM/PM
    %oy  = Original Airdate:  year, 2 digits
    %oY  = Original Airdate:  year, 4 digits
    %on  = Original Airdate:  month
    %om  = Original Airdate:  month, leading zero
    %oj  = Original Airdate:  day of month
    %od  = Original Airdate:  day of month, leading zero
    %%   = a literal % character

# 2  
Old 10-30-2009
Hi mrplow, try this :
Code:
for i in Today Tomorrow Monday Thursday Wednesday Thursday Friday Saturday Sunday; do
  sedstr="${sedstr}s/$(date -d $i +%Y-%m-%d)/$i/;"
done
myth_upcoming_recordings.pl --plain_text --text_format '%Y-%m-%d - %h:%i %A - %T - %S (%cN)\n' --heading "" |
while read date rest; do
  printf "%-10s %s\n" $(echo $date |sed "$sedstr") "$rest"
done

(not surprised you like the simpsons, mr. plow Smilie )

Last edited by Scrutinizer; 10-30-2009 at 11:11 PM..
# 3  
Old 10-31-2009
Geez, I spent my last two lunch hours trying to figure it out. Thanks Scrutinizer. Only problem is the tree spaces after the day, I'd like to squeeze it into the smallest space I can.
Code:
Today      - 09:00 PM - The Simpsons - Treehouse of Horror XIX (COMEDCP)
Tomorrow   - 12:00 AM - Project Runway - A Fashionable New Beginning (SLICE)
Tomorrow   - 12:00 AM - The King of Queens - Court Date (TROPP)
Tomorrow   - 12:30 AM - The King of Queens - White Collar (TROPP)
Tomorrow   - 01:00 PM - Models of the Runway - A Fresh Start (SLICE)

ignore the runway shows, thats for the WAF
# 4  
Old 10-31-2009
The width of the first column is controlled by %-10s . I used 10 so the output would be aligned for the other possible outcomes, e.g.

Code:
Today      - 04:00 PM - Ghost Hunters - Nightmare Noises (OLCC)
Tomorrow   - 05:30 PM - The Simpsons - Treehouse of Horror XI (KCPQ)
Monday     - 06:00 PM - The Simpsons - Treehouse of Horror XII (KCPQ)
Wednesday  - 09:00 PM - The Simpsons - Treehouse of Horror XIX (COMEDCP)
2009-11-08 - 12:00 AM - Project Runway - A Fashionable New Beginning (SLICE)

You can play with that number and see what you like best, e.g. %-8s , %10s, %s etc...
# 5  
Old 10-31-2009
cool thats perfect then, thanks

Previous Thread | Next Thread
Test Your Knowledge in Computers #264
Difficulty: Easy
Alan Turing worked at MIT where he designed the Automatic Computing Engine, which was one of the first designs for a stored-program computer.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Change Date from one format to other

Hi I wish to change date from one format to another in unix. eg: INPUT DATE: 2013159 (YEAR & NUMBER OF DAY) OUTPUT DATE required: 20130608 (YYYYMMDD) how to do it ? Thanks in advance. (6 Replies)
Discussion started by: dashing201
6 Replies

2. Shell Programming and Scripting

Change the date format

Hi, I was looking for a script to change the date from one format to other. A search in the forum gave me the below script as a result. #! /bin/ksh format=YYYYMMDD YEAR=${format%????} DAY=${format#??????} MON=${format#$YEAR} MON=${MON%$DAY} echo $MON/$DAY/$YEAR I got it... (2 Replies)
Discussion started by: prithvirao17
2 Replies

3. Shell Programming and Scripting

Change the date format

Hi all, I have a file that every line starts with the date and time. The format is like YYYYMMDDHHMM and I woulk like to change it to MM/DD/YY<space>HH:MM. I tried to figure out a way to do it with sed, but I don't know how I could reorganize the digits of the first format. Does anyone have any... (1 Reply)
Discussion started by: geovas
1 Replies

4. Shell Programming and Scripting

change date format

Hi, I have the variable "$date_update" in that form: 2011-12-31T13:00:09Z and I would like to change it to 31/12/2011 13:00:09 (Date and Time separated by a blank). Does anyone has a simple solution for that? (using Korn Shell) Cheers Jurgen (4 Replies)
Discussion started by: jurgen
4 Replies

5. Shell Programming and Scripting

Date format change

Dear Friends, Need your help once again, I have a variable ( e.g. ${i}) whoch has date in MM/DD/YYYY (E.g. 12/31/2011) format. I want to change it to DD/MM/YYYY (e.g. 31/12/2011) format. Request you to guide me as we are unable to do the same. Thanks in advance Anu. (1 Reply)
Discussion started by: anushree.a
1 Replies

6. Shell Programming and Scripting

How to change the date format

Hi Guys, Can someone help me on how to change the date format using sed or any unix command to give my desired output as shown below. INPUT FILE: 69372,200,20100122T17:56:02,2 53329,500,20100121T11:50:07,2 48865,100,20100114T16:08:16,2 11719,200,20100108T13:32:20,2 DESIRED... (2 Replies)
Discussion started by: pinpe
2 Replies

7. UNIX for Dummies Questions & Answers

Shell Scripts - shows today’s date and time in a better format than ‘date’ (Uses positional paramete

Hello, I am trying to show today's date and time in a better format than ‘date' (Using positional parameters). I found a command mktime and am wondering if this is the best command to use or will this also show me the time elapse since 1/30/70? Any help would be greatly appreciated, Thanks... (3 Replies)
Discussion started by: citizencro
3 Replies

8. Shell Programming and Scripting

Date Format Change

Hi, Please can I have some command to get yesterday in YYMMDD format? This will be used in ksh Thanks, (2 Replies)
Discussion started by: smalya
2 Replies

9. Shell Programming and Scripting

Date Format Change

Hi I have a date format in a variable as Mon Jan 11 03:35:59 2010. how do i change it to YYYYMMDD format (3 Replies)
Discussion started by: keerthan
3 Replies

10. Shell Programming and Scripting

How to Change the Format of a Date

Hi All, this is my second post, last post reply was very helpful. I have a data that has date in DD/MM/YYYY (07/11/2008) format i want to replace the backslash by a dot(.) so that my awk script can read it inside the C shell script that i have written. i want to change 07/11/2008 to... (3 Replies)
Discussion started by: asirohi
3 Replies

Featured Tech Videos