ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
And I want to search to see if an event is happening, will it be as simple as:
Code:
readline
if element(1) == request(1) and
if element(2) == request(2) and
if element(3) == request(3) then
print all 6 elements to screen
else
read next line
I am more interested in what kind of search this would be. Seems PHP more that enough to take care of my needs. Especially on 'PHP.net'.
Practically, I am not sure whether ultimate end users would key in exact and full dates (they might want a range) or city names. An option would be to have the user select the date (or date range) on line, let the user choose form the drop down list of states (static) and then based on it, cities with open performances.
Secondly, it is generally believed (though I have no proof) that using search tools would be more eficient compared to custom built nested-ifs. I mean once you get the parameters, a sed, grep or awk should do.
Practically, I am not sure whether ultimate end users would key in exact and full dates (they might want a range) or city names. An option would be to have the user select the date (or date range) on line, let the user choose form the drop down list of states (static) and then based on it, cities with open performances.
That is exactly what will happen. I posted the code that wrote that data in another thread. Just need to finish it.
Quote:
Secondly, it is generally believed (though I have no proof) that using search tools would be more eficient compared to custom built nested-ifs. I mean once you get the parameters, a sed, grep or awk should do. OK
Interesting. This would make things so much simpler. Will 'grep' et al be available on linux based servers?
grep, sed, and awk are defined in the POSIX standard as core system tools, so yes, some version should be available on all *nix-based systems.
Almost all Linux distributions use the GNU versions, which have many useful extensions, but the posix syntax should be pretty much universally portable.
Will your search always be the first three comma-delimited data items, as shown in your example?
Or, do you want to search on any number of data items, in any order?
Well, ehow is confirmed as a horrible site to get information from. First off, obviously you'll want to add newlines to the output, because it's completely unreadable. Now, let's look at the official PHP manual page for strpos(), scroll down to the big red Warning box:
Quote:
This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.
If you follow the link to Booleans section you can see that 0 gets converted into FALSE, so if you find match at the beginning of the string, $locationOfString will == FALSE (but not === FALSE).
Okay, so that should tell how to use strpos() correctly, but if you look at what it does: "Find the ... first occurrence of a substring ..." you might realize that it's doing more than you want. Specifically, you only want to match the beginning of the line, not search the entire string. For this task you should use strncmp().
I want to do this on my website. Have clients log in and enter the date state and city they are visiting and get back a list of musicians that are playing on the date they will be there.
If 'grep' is a core unit in Linux, how do I call grep from inside a html/php program on my host server that will read the data file?
I want to do this on my website. Have clients log in and enter the date state and city they are visiting and get back a list of musicians that are playing on the date they will be there.
If 'grep' is a core unit in Linux, how do I call grep from inside a html/php program on my host server that will read the data file?
Oh wow, I am way over my depth here. I suggested grep and gave an example but I know almost zero about html or php or servers. Let's hope one of the LQ Gurus steps forward to address those topics.
#!/bin/bash
# Daniel B. Martin Dec12
#
# To execute this program, launch a terminal session and enter:
# bash /home/daniel/Desktop/LQfiles/dbm568.bin
#
# This program inspired by
# http://www.linuxquestions.org/questions/programming-9/
# what-kind-of-search-routine-do-i-need-4175442825/
Path='/home/daniel/Desktop/LQfiles/dbm568'
InFile=$Path'inp.txt'
CDLs=$Path'cdls.txt'
# Construct a list of concert dates/locations.
# Format of date field is mm/dd/yyyy
cut -d\, -f1-3 $InFile \
|sort -n -k1.7 -k1.1 -k1.4 -u \
|nl -s" " \
> $CDLs
# Solicit user input: select date/location.
echo; echo "Concert dates and locations:"; cat $CDLs
echo
echo "Please enter the NUMBER which identifies the date/location of interest."
read CDLnum
# Establish the Search Pattern.
SP=$(sed $CDLnum'q;d' $CDLs \
|sed 's/^[ \t]*//' \
|cut -d" " -f2-)
# Check the calendar for matches on the Search Pattern.
echo; echo "Concert dates matching" $SP
grep -i ^"$SP" $InFile # Check the calendar for matches
echo
exit
I didn't bother with niceties such as range-checking the user's numerical input. No need for that if your GUI invites the user to make a selection from a pull-down menu.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.