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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:26:16+00:00 2026-05-12T21:26:16+00:00

I have a list with the following content: VIP NAME DATE ARRIVE_TIME FLIGHT_TIME 1

  • 0

I have a list with the following content:

VIP NAME DATE  ARRIVE_TIME FLIGHT_TIME

1  USER1 11-02    20.00    21.00
3  USER2 11-02    20.45    21.45
4  USER2 11-03    20.00    21.30
2  USER1 11-04    17.20    19.10

I want to sort this and similar lists with a shell script. The result should be a new list with lines that do not collide. VIP 1 is most important, if any VIP with a bigger number has ARRIVE_TIME before FLIGHT_TIME for VIP 1 on the same date this line should be removed, so the VIP number should be used to decide which lines to keep if the ARRIVE_TIME, FLIGHT_TIME and DATE collide. Similarly, VIP 2 is more important than VIP 3 and so on.

This is pretty advanced, and I am totally empty for ideas on how to solve this.

  • 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-12T21:26:16+00:00Added an answer on May 12, 2026 at 9:26 pm

    This might get you started:

    • I’m ignoring the header line. You can get rid of it using head or skip it in the for loop.
    • Sort the flights by date, arrival, departure and vip number – having the vip number as a sort key simplifies the logic later.
    • I’m saving the result in an array, but you could redirect it to a temporary file and read it in a line at a time with a while read line; do ...; done <tempfile loop.
    • I’m using indirection to make things more readable (naming the fields instead of using array indices directly – the exclamation point means indirection here instead of “not”)
    • For each line in the result that occurs on the same date as the most recently printed line, compare its arrival time to the previous flight’s departure time
    • Echo the lines that are appropriate.
    • save the date and departure time for later comparison.
    • You should adjust the < comparison to be <= if that works better for your data.

    Here is the script:

    #!/bin/bash
    saveIFS="$IFS"
    IFS=$'\n'
    flights=($(sort -k3,3 -k4,4n -k5,5n -k1,1n flights ))
    IFS="$saveIFS"
    
    date=fields[2]
    arrive=fields[3]
    depart=fields[4]
    
    for line in "${flights[@]}"
    do
        fields=($line)
        if [[ ${!date} == $prevdate && ${!arrive} < $prevdep ]]
        then
            echo "deleted: $line"    # or you could do something else here
        else
            echo $line
            prevdep=${!depart}
            prevdate=${!date}
        fi
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have list in python which has following entries name-1 name-2 name-3 name-4 name-1
I have a list view as following: <ListView x:Name=lvLedger Height={Binding Path=GridHight, ElementName=ledgerList} Width={Binding Path=GridWidth,
I have the following list item that I want to append an 'Edit Settings'
I have the following problem. Each week on a friday a list with content
I have defined a .dir-locals.el file with the following content: ((python-mode . ((cr/virtualenv-name .
I have a list view.Each row of the this listview is the following layout.How
I have created an ExpandableListView with the following code: <ExpandableListView android:id=@+id/android:list android:layout_width=wrap_content android:layout_height=0dp android:layout_marginTop=5dp
I have the following List<int> collection and I need to find the highest integer
I have the following list <ul> <li id=item1>Item 1</li> <li id=item2>Item 2</li> <li>Item 3</li>
I have the following list in Python: [[1, 2], [3, 4], [4, 6], [2,

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.