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 5950565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:24:41+00:00 2026-05-22T17:24:41+00:00

I am trying to figure out the best method to accomplishing this task, where

  • 0

I am trying to figure out the best method to accomplishing this task, where I have a directory that has multiple files with varying file name formats, and I need to parse out those files that have a date in the file name (format of %F, or YYYY-MM-DD) from those that don’t, then iterate through each of them using a mix of a for loop and a case loop to segregate between files that have a date in the file name and those that don’t. Pseudo code is as follow:

#!/bin/bash
files=`ls`
for file in $files; do
  # Command to determine whether $file has a date string
  case (does variable have a date string?) in
    has)   # do something ;;
    hasnt) # do something else ;;
  esac
done

What is the best command to plug in for the comment, and then easiest way to execute such a case statement based off the command?

  • 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-05-22T17:24:41+00:00Added an answer on May 22, 2026 at 5:24 pm

    Given your original code, you can do

    files=`ls`
    for file in $files; do
      # Command to determine whether $file has a date string
      case ${file} in
        *2[0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9]* )   
           # note that this date-only matching reg-exp is imperfect
           # it will match non-dates like 2011-19-39
           # but for cases where date is generated with date %F 
           # it will work OK
           : # do something 
        ;;
        * ) # do something else ;;
      esac
    done
    

    Or as @matchw recommends, you can use that pattern in a find

    find . -type f -name '*2[0-9][0-9][0-9]-[0-1][0-9]-[0-3]-[0-9]*' -print0 \
      | xargs yourCommand
    

    I hope this helps.

    P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out the best way to approach this. I have a
Just trying to figure out what's the best practice: when using method that takes
I have a client/server question that i am trying to figure out the best
Trying to figure out the best way to do this: Should I do something
I'm trying to figure out the best way to do this, but I'm getting
I'm trying to figure out the best method of getting/displaying the shortest distance between
I'm trying to figure out what's the best method to do the following: Let's
I am trying to figure out what would be the best method for storing
While trying to figure out the best method to ping (ICMP) something from python,
I am trying to figure out the best method of displaying a json result

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.