Results 1 to 4 of 4
I am running into an issue that I was trying to figure out on my own but I've sadly hit a brick wall.
What I am trying to do is ...
- 11-09-2007 #1Just Joined!
- Join Date
- Oct 2007
- Location
- Houston
- Posts
- 75
date help
I am running into an issue that I was trying to figure out on my own but I've sadly hit a brick wall.
What I am trying to do is make a script smart enough to be able to take a day that a user inputs (such as Thursday) and search a file for not only the day the user entered but the day before the day the user entered. Then return all the lines that match that along with another variable. I was thinking of using grep to do the wonderful task of searching the file since I can specify -v to get an exact match.
As an example:
User types in Thursday (even though today is Friday). Script takes Thursday and adds Wednesday for grep to search with.
I am also curious is grep or awk faster at searching files and reporting the criteria searched? Or are they about equal?
- 11-09-2007 #2
That shouldn't be too tough. You could even use an if-elif chain to figure out the day before. For instance:
You would obviously want to normalize the string that they entered. I suggest forcing to lowercase and then possibly capitalizing the first letter. Your choice.Code:echo -n "Enter the day to search for: " read today if [ "$today" = "Monday" ]; then yesterday=Sunday elif [ "$today" = "Tuesday" ]; then yesterday=Monday elif ... else echo 'You did not enter a valid date!' fi
As for the second question, I have no proof for my claim, but I would imagine that grep is faster. The only reason for this is that awk is an entire scripting language that is FAR more powerful than grep is. And initializing all of that is probably far more intensive than grep. So if you're not going to use that power, you may as well use grep.
Also, you say that you would use "-v". "-v" actually inverts the match, to show all lines that _DON'T_ match the regular expression.DISTRO=Arch
Registered Linux User #388732
- 11-10-2007 #3Just Joined!
- Join Date
- Oct 2007
- Location
- Houston
- Posts
- 75
Is there not a way to query the shell as well to get that information? I have the script already completed that will run based on the days and this script will actually be ran from a php script.
- 11-10-2007 #4Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Hi,User types in Thursday (even though today is Friday). Script takes Thursday and adds Wednesday for grep to search with.
This command gives a day before the given day:
gives:Code:date --date "Thursday -1 day" +%A
RegardsCode:Wednesday


Reply With Quote