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

  • Home
  • SEARCH
  • 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 6605023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:14:02+00:00 2026-05-25T19:14:02+00:00

I’m writing a bash script and one of the tasks which needs performing is

  • 0

I’m writing a bash script and one of the tasks which needs performing is to connect to an FTP server via curl and find the name of the last modified .zip file.

The name format of the files we are looking at is MM_DD_YYYY_ALL.zip.

So far I have, with omissions in << >>:

export FILEPATTERN=_ALL.zip

for FILE in `curl -u << SERVER INFO >> 2> /dev/null | grep ${FILEPATTERN} | awk -F\  '{print $9}'`
do
    ...
    # Do stuff with each file to determine most recent version.
    ...
done

The fact that the file name isn’t formatted YYYY_MM_DD seems to be the main reason this can’t be done with some quick trimming and calculations.

Is there an efficient way to pull the name of the most recent modified zip file from this list? Or is there some processing which can be done whilst the list is being generated?

Cheers.

  • 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-25T19:14:03+00:00Added an answer on May 25, 2026 at 7:14 pm

    You can sort the filenames in one shot with a multi-key sort command and grab the last line with tail to get the latest file.

    You’ll need to specify -t- to use a dash as sort’s field separator, -n to get a numeric sort, and list each field in the order of its priority. The format for a field specifier is:

    -k, --key=POS1[,POS2]     start a key at POS1 (origin 1), end it at POS2
                              (default end of line)
    

    So for the year, field 3, you’ll need to list it with its 4-character width as -k3,4.

    If you sort by the year, month, and day fields in that order, you’ll end up with a list that has all the files in date order.

    So instead of the for loop above, you can use:

    FILE=`curl -u << SERVER INFO >> 2> /dev/null | grep ${FILEPATTERN} | awk -F\  '{print $9}'
        | sort -n -t- -k3,4 -k1,2 -k2,2 |tail -1`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am writing an app with both english and french support. The app requests
I'm making a simple page using Google Maps API 3. My first. One marker

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.