[bash] help compare date
Hi!
I have a problem with a bash script. My script reads in input a date and a hour; I compare the format of it with regular expression for a completed script. But I could not solve this problem. My code is: Code:
echo "Please insert date [dd/mm/yyyy]: "; read date Also I put result of a grep in an array, is it possible? Can you help me please? |
probably hour is mistyped:
while [ ! ' echo " $hout " | grep -E " ^(([0-1]?[0-9])|(2[0-3]))(:)[0-5]?[0-9]$ " ' ]; |
yes, it is "houR"...but my problems doesn't solved :(
|
You shouldn't be using [ ] there, that is the test builtin command which only checks if the string is not empty:
Code:
while ! echo "$date" | grep -E '[0-9]d{2}/[0-9]d{2}/[0-9]d{4}' ; |
probably I do not understand, but what is that d in the regexp:
while ! echo "$date" | grep -E '[0-9]d{2}/[0-9]d{2}/[0-9]d{4}' ; I think they should be removed |
I recommend a slightly different approach:
Code:
#!/bin/bash Follow this up with a similar loop for the hours. |
Thank you so much!!!
I have other problems... I insert this information in a file and I research with a grep an occourrence. The result of grep is composed from 4 elements and I need to printed 4° elements, even if there are 3 (in example). I tried: Code:
array=( $(grep "$occ" .eventi.txt) ) I created a background process with the fuction that does it... How I kill this child process, before exiting the program? I don't know the PID... Can you help me, please?:( |
We really need to see the input data, at a minimum, if you want proper help from us.
Please give us an example of the contents of the file, and point out what you need from it, in detail. Also post the function code you wrote, if possible. And what does the $occ variable contain? At the very least, this... Code:
array=( $(grep "$occ" .eventi.txt) ) (*Unless you've reset the IFS environmental variable in some way, then it will split on whatever characters it contains.) Safe processing would probably require another read loop or similar. But again we need to see what the input looks like. |
I'm sorry! you're right!
My script reads the following input data: name, date, hour and a message. With this informations it creates an event and my file contains a list of these events. For example Code:
name-event1 09/05/2000 15:40 message1 I put in $occ current date and current hour for "grep". So, the output is "name-events date hour message" But I have to print only the message of occurring event. For example the 04/04/2004 at 04:04 my script print "message1". I had thought to put my grep result into an array and after to print only 4th element...but i have problems if multiple events occur! Also...to close the script I must kill background process. to kill process I need its PID. I can use "ps" command and copying the ouput in a file, so I can use another "grep" that give me only PID...I'm in a bind...:banghead: |
You should explain what you are trying to do, not how to do it.
(I tell this to my boss all the time) I would say you may be making life hard for yourself. |
I tried again ...
My script like as a memo. if I want to remember a meeting between 5 minutes, I'll have a background process that between 5 minutes print "you have a meeting!" When I close the script I must kill the background process |
All times are GMT -5. The time now is 05:38 AM. |