To grep a text from a list of files.
hi all,
I want to locate a file which contains a particular script, say "xxxx". The file is located along with millions of files , inside a directory. The only clue , i have is ,the text is inside a file which is created on 12th feb. I used "ls -ltr |grep -e "Feb 12" to list the files. Here i get thousands of files. how can i isolate the file which contains my text "xxxx" from the output of "ls -ltr |grep -e "Feb 12" Please assist. Thanks |
You might try something like this. I put grep inside of the find command.
Code:
touch --d 20080213 end Assuming you won't run out of memory, this will list just the filenames from the last field: Code:
ls -l | awk 'BEGIN {FS=" *"} /Feb 12/{ print $NF }' Code:
for file in $(ls -l | awk 'BEGIN {FS=" "} /Feb/{ for (i = 9; i <= NF; i++) printf "%s ", $i; printf "\n"}'); do |
Note that the date reported by ls is not the file creation date - it is the file modification date. Linux (and unix-like OSes in general) do not keep the creation date. In the case where the file has not been modified since it was created, it is the same thing but if the file has been modified, the creation date is lost (unless the creation date is part of the file name).
|
Thank you both...
I am going with find ./dir -maxdepth 1 -type f -print0 | xargs -0 --max-args=200 grep -e 'xxxx' |
Have you looked at the -l option for grep?
Code:
find . -name "*" -exec grep -l xxxx '{}' \; |
All times are GMT -5. The time now is 06:04 AM. |