AlMehdi
AlMehdi

Reputation: 557

How can i switch place of hour and minutes from a clock command (for crontab) using awk

I want to use a command to make a crontab that plays an alarm (for my wife). The program is called ipraytime and it gives an output like this.

$ ipraytime -u +2

Prayer schedule for,
City             : Custom
Latitude         : 021�� 25' 12" N
Longitude        : 039�� 49' 47" E
Angle Method     : Umm Al-Qurra University
TimeZone         : UTC+2.0
Qibla            : 061�� 45' 42" W of true North

     Date         Fajr    Shorooq   Zuhr     Asr    Maghrib   Isha 
--------------------------------------------------------------------
[09-05-2012]     4:19     5:43    12:16    15:35    18:48    20:18

Today's Imsaak    :   4:11
Tomorrow's Imsaak :   4:10
Tomorrow's Fajr   :   4:18

What i want is that the times format good for a crontab which means i need to switch places of the minute and hour. To be 19 4 instead.

I have made this command but don't know how to make that switch.

ipraytime -u +2| awk 'NR==12 {print $2"\n"$3"\n"$4"\n"$5"\n"$6"\n"$7}' | sed 's/:/ /g'

This gives me an output like this

4 19
5 43
12 16
15 35
18 48
20 18

But i want it to be like this

19 4
43 5
16 12
35 15
48 18
18 20

As that is what a crontab is using. I have played with sort a bit but couldn't find a solution there either.

(Sorry for the bad topic.. didn't know how to write a good one for this)

Upvotes: 0

Views: 100

Answers (2)

Dennis Williamson
Dennis Williamson

Reputation: 360365

It's not necessary to use sed at all.

$ ipraytime -u +2 | awk -F ' +|:' 'NR == 12 {for (i = 2; i <= 12; i += 2) print $(i+1), $i}'
19 4
43 5
16 12
35 15
48 18
18 20

Upvotes: 2

Prince John Wesley
Prince John Wesley

Reputation: 63708

Use sed 's/\(.*\):\(.*\)/\2 \1/'

Command:

ipraytime -u +2 | awk 'NR==12 {print $2"\n"$3"\n"$4"\n"$5"\n"$6"\n"$7}' 
 | sed 's/\(.*\):\(.*\)/\2 \1/'

Upvotes: 1

Related Questions