![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| filtering list results | fxvisions | Shell Programming and Scripting | 3 | 10-10-2007 07:57 PM |
| My ps -ef|grep command results are chopped off | bsp18974 | UNIX for Dummies Questions & Answers | 1 | 08-14-2007 10:35 AM |
| How to display first 7 char of grep results? | kthatch | UNIX for Dummies Questions & Answers | 8 | 04-05-2007 01:00 AM |
| How to refine results of grep -p | priceb | Shell Programming and Scripting | 2 | 06-28-2006 08:40 AM |
| Multiple Grep Results - Formatting | sysera | Shell Programming and Scripting | 7 | 03-25-2004 06:04 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
List grep results
Hi
I need to search for matching strings in a database and I want to print out all files that matches in "detail", which means that I want the output to contain datum of last saving. I only get the grep function tp print the actual file names which is not enough since the database is to large and I need to sort in date.... Greatful for all help, Ola |
|
||||
|
slire,
Its not possible to get the file creation date in UNIX. Thats the answer i have got after going thru the threads on this topic. The only things u can get are time of last modification n time of last access. Weird, but apparently true. |
|
||||
|
Try this
The ls command has a couple of switches here that might accomplish what you are looking for. After reading this, do a man ls on whatever flavor of Unix you are using in case the exact letter used for the switch is different.
First, ls -lc will usually give you a timestamp of when the file was last modified. Secondly, ls -lu will usually give you a timestamp of when the file was last accessed. So, if a file has been created and never accessed (and hence never modified), an ls -lu command will report the timestamp of when the file was created. But the next time you access the file, that timestamp is updated. Now, if you are trying to figure out which files are older than other files, you could try this: ls -lct /directory -l --> Gives the long listing, which includes the timestamp -c --> Gives a timestamp of when the file was last written to -t --> sorts the output so that the files most recently modified are at the top and the older modification times are at the bottom. So, combining all of this with what I've gathered from your other posts: from your home directory: grep <whatever it is your looking for> /directory/of/*.dbf > somefile Now, if you did a more on somefile the entry will probably look like this: <the name of the file containing the string>:<the string you searched for> Now, you want to get information on that file. If there are only a handful of lines, you could open somefile in vi and manually delete everything after the colon, which just leaves the filename. But, if you end up with dozens or even hundreds of entries, we need a more efficient way to parse out the filename. awk -F: '{print $1}' somefile > somefile2 mv somefile2 somefile We now have a list of all files in the /directory/of/*.dbf that match the string you wanted. Now to get information on those files. for filename in `cat somefile` do ls -lc $filename >> somefile2 done mv somefile2 somefile Finally, more somefile. ** You'll note in my for loop I did not use the -t flag on the ls command. Since we're getting info on files one at a time, their really isn't a way to sort them here. Once we get all the output into a text file, you could use awk and sort to put them in order if you needed. ** It kinda long and ugly, but from what you told me this should get the job done. Did this answer your question or did I go WAAAYYYY out in left field? - HK |
|
||||
|
Thanks for the answer, but since I am very unexperienced with UNIX and programing I dont really understand how to proceed with the following commands.
for filename in `cat somefile` do ls -lc $filename >> somefile2 done mv somefile2 somefile Should I write this in a script? In that case I don't really now how to do it, can u possibly give un example. Sorry for my low level of understanding.... |
| Sponsored Links | ||
|
|