The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-24-2006
slire slire is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 7
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
  #2 (permalink)  
Old 10-24-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
Code:
grep 'whatever detail I need'  /path/to/db/files/*.dbf
  #3 (permalink)  
Old 10-24-2006
slire slire is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 7
Sorry, maybe I was a bit unclear, but the problem is a little bit more complicated, that commando will only print the file name and not any other information, like date whem file was created.....
  #4 (permalink)  
Old 10-24-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
mc is the bane of unix - IMO
redirect the output to a file, then edit the output file...

Code:
grep 'whatever detail I need'  /path/to/db/files/*.dbf > outputfile
then open outputfile an read it.
  #5 (permalink)  
Old 10-25-2006
napolayan napolayan is offline
Registered User
  
 

Join Date: Oct 2006
Location: Bangalore, India
Posts: 41
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.
  #6 (permalink)  
Old 10-25-2006
Heathe_Kyle Heathe_Kyle is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 15
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
  #7 (permalink)  
Old 10-27-2006
slire slire is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 7
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:42 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0