Originally Posted by JamesQQ
Im trying to create a booking system. Every time the user select one of the seats it will register to the text file but there will be different date and time.
So for example
The user register for seat A1 to monday 9.30pm.
Monday 8pm - B3,A2
Monday 8.30pm - B1,B2
Monday 9.30pm - A2,A3
how do i add in behind A3 for 9.30PM?
I think your problem is to find out what the right position in the file is, correct? I.e. you want the file to be sorted by date and time.
In this case I would just add the line at the end (echo registrationstring >> textfile) then sort the file. The sort command should be powerful enough to do it right.
If you have control over the format of the text file, you may want to use a format that is easier to sort, e.g. instead of 8pm, always write 8.00pm or even 20.00.
Alternatively an awk program to find the right position, but that is probably more complex and error prone, and not necessarily more performant.