new_perl_user
asked on
grep a file by date
Hi,
How to grep a file by its date as filename. For example test_20111003114318.txt. I tried something like below
egrep -v "^$|[/]$" test_20111003114318.txt
But I don't want to hard code the name as above , because I need to go and change it everyday..
How to grep a file by its date as filename. For example test_20111003114318.txt. I tried something like below
egrep -v "^$|[/]$" test_20111003114318.txt
But I don't want to hard code the name as above , because I need to go and change it everyday..
you could make a bash script which takes the date as an argument and then implements it into the command?
Save as dgrep and run ./dgrep 20111003114318 to find the file. I believe the script is correct, i will test it when i get my linux machine online
#! /bin/bash
# run egrep on date
egrep -v "^$|[/]$" test_$1.txt
ASKER
can I implement in the above command.
something like egrep -v "^$|[/]$" test_$date.txt
something like egrep -v "^$|[/]$" test_$date.txt
My solutions is to create a new file, dgrep in your current working directory. Copy/paste my code into this file, and then run chmod +x dgrep
Then you can run ./dgrep 2020204083 and it will run the search.
$1 is the reference to the first command line argument passed to the script, the name is not arbitrary
Then you can run ./dgrep 2020204083 and it will run the search.
$1 is the reference to the first command line argument passed to the script, the name is not arbitrary
ASKER
what if I automate the process rather than running it from command line
Do you need to grep filenames with specific timestamps or can you glob it? If you need specific dates, how do you determine which dates need to be passed to the script?
ASKER
it always will be the sysdate. No worries about time. If it will able to pick up file by sysdate then it should be fine.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.