Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8554489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:53:39+00:00 2026-06-11T14:53:39+00:00

I hope one of you bash, sed, awk experts out there can help me

  • 0

I hope one of you bash, sed, awk experts out there can help me out. I have this string:

 00:00:00:00:00:00%~%System1%~%s0:00-21:40%~%m3:10-17:10%~%t11:20-20:30%~%w05:10-9:30%~%t00:00-21:30%~%f12:00-0:00%~%s6:00-18:00     

It is fields separated by “%~%”. The first two fields can be ignored. The remaining fields have day time ranges. This should clarify the format:

00:00:00:00:00:00 <--Mac
System1           <--Name
s00:00-21:40      <--Sunday 12 AM through 9:40 PM  
m03:10-17:10      <--Monday 3:10 AM through 5:10 PM
t11:20-20:30      <--Tuesday 11:20 AM through 8:30 PM
w05:10-9:30       <--Wednesday 5:10 AM through 9:30 AM
t00:00-21:30      <--Thursday 12 AM through 9:30 PM
f12:00-0:00       <--Friday 12 PM through 12:00 AM
s06:00-18:00      <--Saturday 6 AM through 6:00 PM

Now the trick…I need to determine if the current system datetime is within the ranges. 🙁

So, if date returns this:

 Wed Sep 19 14:26:05 UTC 2012

Then it doesn’t fall within the range specified for Wednesday. I basically need an if statement. I need to execute one script if it is within the range and a different script if it is not. How would I do that with bash, awk, and/or sed?

Thanks for any help you can offer!

I started going down this path:

arr=$(echo $line | tr "%~% " "\n")
for x in $arr
do
    #Now what?  Some kind of switch/case?
done
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:53:40+00:00Added an answer on June 11, 2026 at 2:53 pm

    I believe that the following script does what you want:

    #!/bin/bash
    
    # Function which returns true (0) on a time being in a range, false (1) otherwise
    # call as: time_between $time $range
    # where $range is of the format 'START-END'
    time_between() {
        current_time=$1
        range=$2
    
        start_time=$(echo $range | cut -d'-' -f1);
        end_time=$(echo $range | cut -d'-' -f2);
    
        # Correct if ends at midnight
        if [[ $end_time -eq 0 ]]; then
            let end_time=2400
        fi
    
        # Test is time is within the window
        if [[ $current_time -ge $start_time && $current_time -le $end_time ]]
        then
             return 0;
        fi
    
        # Else the time is outside the window
        return 1;
    }
    
    # Set the line variable - you may want this to come from somewhere else in the end  
    line="00:00:00:00:00:00%~%System1%~%s0:00-21:40%~%m3:10-17:10%~%t11:20-20:30%~%w05:10-9:30%~%t00:00-21:30%~%f12:00-0:00%~%s6:00-18:00"
    
    i=0
    
    # Extract the day and time (hours and minutes) from the `date` command
    DATE=$(date)
    day=$(echo $DATE | cut -d' ' -f1)
    
    time=$(echo $DATE | cut -d' ' -f4 | cut -d: -f1-2 | tr -d ':')
    
    # Marker for which token in the line to start the days from: token 3 is monday
    dayno=2
    
    # Set the dayno so we're pointing at the current day
    case $day in
    Mon)
        let dayno+=1
    ;;
    Tue)
        let dayno+=2
    ;;
    Wed)
        let dayno+=3
    ;;
    Thu)
        let dayno+=4
    ;;
    Fri)
        let dayno+=5
    ;;
    Sat)
        let dayno+=6
    ;;
    Sun)
        let dayno+=7
    ;;
    esac
    
    arr=$(echo $line | tr '%~%' '\n' | tr -d '[a-z]:')
    
    for x in $arr
    do
        let i+=1;
        #Now what?  Some kind of switch/case?
        if [[ $i -eq $dayno ]]; then
            if time_between $time $x; then
                echo "Were within the window!"
            else
                echo "We missed the window!"
            fi
        fi
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a big problem I hope some one can help me with it.
I have a mysql issue. Hope one of you can help me! I have
Hope the AWK gurus can provide a solution to my problem . I have
here is my next question and i hope some one can help me :-)
I'm stuck in a rut. I hope some one can help. Basically, I am
I have a problem and I hope one of you can suggest a better
There is one thing I never understood about references and I hope that one
I hope this is an easy one. Using MVC4 with Entity Framework 4.1. I'am
I hope it's the heat, this is the second question today and it's one
I think I already know the answer to this one, but i hope maybe

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.