find and write


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers find and write
# 1  
Old 09-18-2003
find and write

Hi,

I was able to succesfully search/find the files I needed using the command : find . -exec grep string {} /dev/null \; however,
I would like to have the result written in a log file.

Can someone please show me how to do this?

Thanks in advance.
Bong
# 2  
Old 09-18-2003
Just redirect the output to a log file using >

e.g.

find . -exec grep string {} \; > ./mylog

Matt.
# 3  
Old 09-18-2003
Hi Bong,

In addition again :

for speeding up your find command try to be more specific :

find . -type f -exec grep string {} \;

If you specify to only grep files, it speeds up definitly. Also redirecting output is one of the standards you have to understand. So therefor a little story Smilie

When specify-ing > you say that all output generated should be redirected. By specify-ing > you actualy say 1>. As you are telling only standard output to be redirected.

You have :
0 --> Standard input
1 --> Standard output
2 --> Standard error

So to make things a bit more complicated :

ls -l /tmp 1> /tmp/output 2>/dev/null

Standard output is written to a file and standard Error is being thrown away (/dev/null is a kind of paper.bin)

ls -l 1>> /tmp/output 2>&1

Standard output is appended to a file and standard error is redirected to standard output.

Good luck.

Regs David
# 4  
Old 09-18-2003
In addition to davidg's suggestion for find: If you will be finding a lot of files and then grepping them, you can save a good bit more time by feeding more file names to grep at once using xargs, thus:

find . -type f | xargs grep string

This has the side benefit of printing the file names with each file in which your string is found. If there are too many files to put on one command line (for the grep part), xargs will split the names according to your system's command line rules (which vary frustratinglySmilie and provide another motivation for using xargs). If there is only one file in the last "group" that xargs feeds to grep, however, its filename won't be printed (unless your grep has an option to force the filename).
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find matches and write the data before it

Hi all I am here for help once again I have two files One file is like this with one columns F2 B2 CAD KGM HTC CSP Second file is like this in 5 columns where firs column contain sometime entries of first file with space and other entries (12 Replies)
Discussion started by: Priyanka Chopra
12 Replies

2. Shell Programming and Scripting

Request to check: find common and write before it

Hi all, I have 2 big files with such kind of inputs File I File II I want the output file shuld contain Please let me knw scripting regarind this (1 Reply)
Discussion started by: manigrover
1 Replies

3. Shell Programming and Scripting

perl script to find, write, repeat...

I am a novice writing perl scripts so I'd appreciate any help you guys can offer. I have a list of 100 words in a file (words.txt) and I need to find them in a second file (data.txt). Whenever one of these words is found I need to write that line to a third file (out.txt) and then continue... (1 Reply)
Discussion started by: tgamble
1 Replies

4. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

5. UNIX for Dummies Questions & Answers

How to find out in which directories a user can write?

Hi everybody, what command can show me the directories in which a certain user can write to? Kind Regards FranzB (2 Replies)
Discussion started by: FranzB
2 Replies

6. Shell Programming and Scripting

Find all files with group read OR group write OR user write permission

I need to find all the files that have group Read or Write permission or files that have user write permission. This is what I have so far: find . -exec ls -l {} \; | awk '/-...rw..w./ {print $1 " " $3 " " $4 " " $9}' It shows me all files where group read = true, group write = true... (5 Replies)
Discussion started by: shunter63
5 Replies

7. Shell Programming and Scripting

Find and write to a files

Hello my friends,I'm a new learner to programming in Linux so kindly can you help me to write this simple script for me and it is lists all text files "*.TXT" in a directory and writes the first line of each text-file to a file called "Aby_Name". Thank you so much. (12 Replies)
Discussion started by: Net-Man
12 Replies

8. Shell Programming and Scripting

Please help me to write a Script to find out whether website is up!!!!!!!

Hello friends I have to write a script in linux to find out the website is up or down..... Please help me in this thank you Jay (1 Reply)
Discussion started by: jai143
1 Replies

9. UNIX for Dummies Questions & Answers

how to write to file using fprintf in find command...

:D I once again am looking through the man pages and am still working on the find command to fully comprehend all its attributes.. i am a little stuck on a problem with how many options to -print there are and the only two I know how to use are printf and -print.. i can not make heads or tails of... (2 Replies)
Discussion started by: moxxx68
2 Replies

10. UNIX for Dummies Questions & Answers

help me write a find command

At times I have thse Oracle logfiles that grow like crazy and fill up a specific file system. I wanted to write a find command that lists which are the biggest files from the search path..so /qbidora02/oracledba/find . -name ....... <downward to the lowest level> and list file names, sizes and... (2 Replies)
Discussion started by: jigarlakhani
2 Replies
Login or Register to Ask a Question