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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:04:54+00:00 2026-05-27T18:04:54+00:00

I have a normal… for file in * do #do something here done …Code.

  • 0

I have a normal…

for file in *
do
    #do something here
done

…Code.
The problem is that I want to sort the row of the files by a custom date, the date is defined in the second line of the files.
I got to problems here:

1.How do I find out what’s in the second line of these multiple files before I actually run

for file in * do

2.How do I sort the loop by this custom string then?

This doesn’t work but maybe it will help you understanding my problem:

for file in *
do
    customdate="$(sed -n 2p $file)"
done

for file in * sort by $customdate
do
    #do something here
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-05-27T18:04:55+00:00Added an answer on May 27, 2026 at 6:04 pm

    I think you need two loops. The first list reads that date out of the files and builds an index. and the second loop goes through that index. You can use a delimiter to split the index out again to get the filename out of the index again.

    index=""
    for file in *
    do
       customdate="$(head -2 $file | tail -1)"
       index="${index}${customdate},${file}\n"
    done
    
    for key in `echo -e ${index} | sort`
    do
       customdate=${key/,.*/}
       file=${key/.*,/}
       # PROCESS FILE HERE
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a normal asp.net page containing some code that I want to measure
Is it normal to have tests that are way bigger than the actual code
Imagine you have a normal table view where each row is an item on
I have read that 'Normal' ARM instructions are fixed length - 32 bits. And
I have an app that normal users need to be able to run, but
I have the normal PayPal donation button. I want to add two multiple choice
I have a normal pdf file A.pdf , a third party encodes the file
I have normal java installed already. now I want to install a software which
We have normal java files residing in the SVN. We have made some changes
I have a normal WinForms ToolStripDropDownButton's drop down menu that is populated dynamically. In

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.