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.
I wrote the following as our developers won't do it for us! The rest of my programming is in PHP, any ideas on how I can get this into php?
I'm in the middle of writing a reminder system which involves importing the customer data and sending out reminder emails.
All the script below does is download the current report $FILEIN, compare field number 6 ($DATA) with the date($DATE), if there is a match, it checks each line in the prescription_skus.csv to see if there is a match with field number 1 in the current report. It then outputs the entire line to $FILEOUT
Code:
TODAY=`date +"%Y-%m-%d"`
FILEIN="export-"$TODAY".csv"
FILEOUT="report"`date +"%Y-%m-%d"`
DATE=`date --date="1 days ago" +"%Y-%m-%d"`
INDATE=$1
wget http://mysite.co.uk/$FILEIN
if test -z "$1"; then
cat $FILEIN | while read line; do
DATA=`echo $line | cut -d ',' -f 6 | awk '{ print $1; }'`
if [ "$DATA" = "$DATE" ]; then
if cat prescription_skus.csv | grep -q `echo $line | cut -d ',' -f 1`
then echo $line >> $FILEOUT;
fi
fi
done
else
cat $FILEIN | while read line; do
DATA=`echo $line | cut -d ',' -f 6 | awk '{ print $1; }'`
if [ "$DATA" = "$1" ]; then
if cat prescription_skus.csv | grep -q `echo $line | cut -d ',' -f 1`
then echo $line >> $FILEOUT;
fi
fi
done
fi
You'll need to break this up a bit - first isolate the thing you want to match, using explode() as detailed above. Then you'll need to open the file, read it line-by-line and use preg_match() to see if there are any matching lines.
Code:
then echo $line >> $FILEOUT;
This is just opening and writing to a file again.
Code:
fi
fi
done
else
You shouldn't need help with this bit
Code:
cat $FILEIN | while read line; do
DATA=`echo $line | cut -d ',' -f 6 | awk '{ print $1; }'`
if [ "$DATA" = "$1" ]; then
if cat prescription_skus.csv | grep -q `echo $line | cut -d ',' -f 1`
then echo $line >> $FILEOUT;
fi
fi
done
fi
Same as similar sections of code above.
Hopefully this will give you a decent start to writing your PHP code... If you still have problems, do post back the code you have written and I would be more than happy to look at it
Hope this helps,
Last edited by Snark1994; 07-05-2011 at 04:54 PM.
Reason: Finishing off my earlier post
Can't you run it with test data? Like, edit daily and put in yesterday's date where it would normally appear and see if the script works. You would just have to ensure that "daily" downloads properly, and you can be fairly sure that the script works.
However, if you consider the problem solved, could you mark it as such using the thread tools please? Thank you
Our developers are letting me download the file now, so I can give it a test.
It's not actually resolved as it seems when a match is found, it doesn't iterate properly through every line of prescription_skus.csv and properly identify a match, it gets stuck on the first line.
This part is meant to iterate through the lines but doesn't
It also doesn't output the whole line to the file, only something like this
Interesting change, but it doesn't fix the problem that the lines aren't matching and that it doesn't parse the prescription_skus.csv file properly - it's stuck on the first line and doesn't go to the second line. The file is just like this
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.