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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:39:02+00:00 2026-05-18T05:39:02+00:00

I am trying to develop a system where this application allows user to book

  • 0

I am trying to develop a system where this application allows user to book ticket seat. I am trying to implement an automatic system(a function) where the app can choose the best seats for the user.

My current database(seats.txt) file store in this way(not sure if its a good format:

X000X
00000
0XXX0

where X means the seat is occupied, 0 means nothing.

After user login to my system, and choose the “Choose best for you”, the user will be prompt to enter how many seats he/she want (I have done this part), now, if user enter: 2, I will check from first row, see if there is any empty seats, if yes, then I assign(this is a simple way, once I get this work, I will write a better “automatic-booking” algorithm)

I try to play with sed, awk, grep.. but it just cant work (I am new to bash programming, just learning bash 3 days ago).

Anyone can help?

FYI: The seats.txt format doesn’t have to be that way. It can also be, store all seats in 1 row, like: X000X0XXX00XXX

Thanks =)

  • 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-18T05:39:03+00:00Added an answer on May 18, 2026 at 5:39 am

    Here’s something to get you started. This script reads in each seat from your file and displays if it’s taken or empty, keeping track of the row and column number all the while.

    #!/bin/bash
    
    let ROW=1
    let COL=1
    
    # Read one character at a time into the variable $SEAT.
    while read -n 1 SEAT; do
        # Check if $SEAT is an X, 0, or other.
        case "$SEAT" in
            # Taken.
            X)  echo "Row $ROW, col $COL is taken"
                let COL++
                ;;
    
            # Empty.
            0) 
                echo "Row $ROW, col $COL is EMPTY"
                let COL++
                ;;
    
            # Must be a new line ('\n').
            *)  let ROW++
                let COL=1
                ;;
        esac
    done < seats.txt
    

    Notice that we feed in seats.txt at the end of the script, not at the beginning. It’s weird, but that’s UNIX for ya. Curiously, the entire while loop behaves like one big command:

    while read -n 1 SEAT; do {stuff}; done < seats.txt
    

    The < at the end feeds in seats.txt to the loop as a whole, and specifically to the read command.

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

Sidebar

Related Questions

I'm trying to develop an online formbuilder. Each user can build their own forms
I am trying to develop everything in sharepoint as features so I can easily
I'm trying to develop an application that will use getImageData in javascript in Firefox
I'm trying to develop a little C# application (with MS Visual Express and SQL
I am trying to develop a iphone app by using cocos2d. I create a
I'm trying to develop a cross platform application, where the most obvious route would
I am trying to develop a util (using system-hook) for that works like an
I am trying to develop an application for a Windows Mobile PDA , but
I'm trying to develop a simple homework submission system with Java. I'm working on
We are trying to develop a real-time display system in safety critical domain. (All

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.