List grep results


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers List grep results
# 1  
Old 10-24-2006
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  
Old 10-24-2006
Code:
grep 'whatever detail I need'  /path/to/db/files/*.dbf

# 3  
Old 10-24-2006
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  
Old 10-24-2006
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  
Old 10-25-2006
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  
Old 10-25-2006
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  
Old 10-27-2006
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....
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cannot get results from grep command

Hi, i have a file hello.log which as several line that look like the below 2015-12-07 09:46:56 0:339 120.111.12.12 POST /helloWorld 2015-12-07 09:46:57 0:439 122.111.12.12 POST /helloWorld .... when i grep expecting to see results like the below. ... (6 Replies)
Discussion started by: mohtashims
6 Replies

2. Shell Programming and Scripting

How to concatenate grep results?

hi, let's say we have input in files test1.txt, test2.txt, text3.txt ... ... ... ('...' means more files & lines not just 'dots') test1.txt has: A B C D ... ... ... test2.txt has A B C D ... ... ... (4 Replies)
Discussion started by: msonoth
4 Replies

3. UNIX for Dummies Questions & Answers

Grep not giving expected results

Version: RHEL 5.8 I am doing a grep of the piped output from ps command as shown below. I am grepping for the pattern ora_dbw* . But, in the result set I am seeing strings with ora_dbr* as well like ora_dbrm_SDLM1DAS3 as shown below. Any idea why is this happening ? $ ps -ef | grep... (6 Replies)
Discussion started by: John K
6 Replies

4. Shell Programming and Scripting

How to analyse results of grep

Hi all, I'm working with a peice of software that runs on Linux that allows planning trips in cars through maps. This software has different variations depending on the type of car, e.g. BMW, Audi, Hyundai, etc... Each variation has a dependency on common external components that are not... (1 Reply)
Discussion started by: emoshaya
1 Replies

5. UNIX for Dummies Questions & Answers

How to do ls -l on results of grep and find?

Hi, Am running the command below to search for files that contains a certain string. grep -il "shutdown" `find . -type f -mtime -1 -print` | grep "^./scripts/active" How do I get it to do a ls -l on the list of files? I tried doing ls -l `grep -il "shutdown" `find . -type f -mtime -1... (5 Replies)
Discussion started by: newbie_01
5 Replies

6. Shell Programming and Scripting

Grep no results

Hello guys, I have been looking around but can't find the answer to my problem: If the grep command displays no results, print "no results have been found" and increment x. But if the grep command find something, do nothing. if echo "no results have been found $x" x=`expr $x + 1 `... (3 Replies)
Discussion started by: Benou
3 Replies

7. Shell Programming and Scripting

Adding grep'd results in a variable

Here is one I am baffled with; I have not used unix for a while and now that I am back it has been fun remembering and I have enjoyed it, for the most past. this is in ksh. I need to search in a file for the line with X1 and cut columns 20-25, put them into a variable, added them (dollar... (3 Replies)
Discussion started by: CougarMutt
3 Replies

8. Shell Programming and Scripting

Selecting patterns from the results of grep

Hi All, I'm struggling with a problem that I'm wondering (and hoping!) that someone can help me with. I have a number of .xml files which I'm using grep to search for the string 'include'. I need to extract the value of the include from the grep result. For example, on any given file, I... (2 Replies)
Discussion started by: Steve_altius
2 Replies

9. UNIX for Dummies Questions & Answers

My ps -ef|grep command results are chopped off

On our one HP-UX 11i box, we have some very long paths defined. When I want to check on our user processes running, the resulting paths are chopped off. /xyz/abc/123/......./server/b is really a process running in the ..../server/bin directory. Is this a terminal problem or buffer length... (1 Reply)
Discussion started by: bsp18974
1 Replies

10. Shell Programming and Scripting

How to refine results of grep -p

I need help to further reduce the output shown below. I want to be able to only return the paragraph where the 'Database alias' is exactly equal to DBIHP. I do not want the other paragraphs being shown below. $ echo $dbalias DBIHP $ db2 list db directory|grep -p 'Database alias ... (2 Replies)
Discussion started by: priceb
2 Replies
Login or Register to Ask a Question