Redirect grep error/result to file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Redirect grep error/result to file
# 1  
Old 01-23-2012
Redirect grep error/result to file

I'm having trouble piping grep results/error to a file. Why can't I redirect these messages into a file?

Code:
$ grep -r -o "pattern" * > log
   Binary file foo1 matches
   Binary file foo2 matches
   Binary file foo3 matches
   Binary file foo4 matches

The log is created, but remains empty.

---------- Post updated at 05:02 PM ---------- Previous update was at 04:53 PM ----------

Code:
$ find * -exec grep -Hn "pattern" {} \; > log

# 2  
Old 01-23-2012
It may be printing them to stderr. I don't understand why it'd do that either, but if so, you can just do 2> logfile
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep output to file result not as expected

Hi Gurus, I run command grep ABC file1 > file2 against below file. I got all ABC_xxx in one line in file2. I expect to get multiple lines in file2. If I print result in screen, the result is expected. thanks in advance My os is SunOS 5.10 Generic_150400-64 sun4v sparc sun4v ABC_123 XXXXX... (2 Replies)
Discussion started by: green_k
2 Replies

2. Shell Programming and Scripting

Redirect script output to file after grep

i have simple program that generate log file 1 line every sec, i need to do grep for specific record then redirect to another file. #!/bin/bash for i in `seq 1 20`; do echo $i sleep 1 done ./test.sh |egrep "5|10|15" 5 10 15 r ./test.sh... (2 Replies)
Discussion started by: before4
2 Replies

3. Shell Programming and Scripting

Output block of lines in a file based on grep result

Hi I would appreciate your help with this. I have a output file from a command. It is broken based on initial of the users. Exmaple of iitials MN & SS. Under each section there is information pertaining to the user however each section can have different number of lines. MY challenge is to ... (5 Replies)
Discussion started by: mnassiri
5 Replies

4. UNIX for Dummies Questions & Answers

Bash - CLI - grep - Passing result to grep through pipe

Hello. I want to get all modules which are loaded and which name are exactly 2 characters long and not more than 2 characters and begin with "nv" lsmod | (e)grep '^nv???????????? I want to get all modules which are loaded and which name begin with "nv" and are 2 to 7 characters long ... (1 Reply)
Discussion started by: jcdole
1 Replies

5. UNIX and Linux Applications

How to redirect grep command output to same file

Hi Everyone, Can anyone please tell me, how can I redirect the grep command output to same file. I am trying with below command but my original file contains no data after executing the command. $grep pattern file1 > file1 Kind Regards, Eswar (5 Replies)
Discussion started by: picheswa
5 Replies

6. AIX

Grep multiple lines and redirect to file

I have setof files with data and with same fields multiple times in each of the files. for example: file 1 name = mary kate last name = kate address = 123 street = abc name = mary mark last name = mark address = 456 street = bcd file 2 name = mary kate last name = kate... (2 Replies)
Discussion started by: relearner
2 Replies

7. Shell Programming and Scripting

how to redirect the output of a grep command to a file inside a shell script

hi, i wat to get the output of a grep command in a file. but when i am trying out the same grep command in the unix prompt its working fine.. i am getting the output properly.. but when i am writing the same command inside my shell script , its just creating a new output file with no contents... (11 Replies)
Discussion started by: kripssmart
11 Replies

8. HP-UX

How to Redirect the error messages from Syslog file to our own Application Log File

Hello, I am New to Unix. I am Using HP-UX 9000 Series for my Application. I am Currently Facing an Issue that the error messages are being written in the syslog file instead of the Application Log File. The Codes for that Syslog.h is written in Pro*C. I want to know how to Redirect these... (3 Replies)
Discussion started by: balasubramaniam
3 Replies

9. Shell Programming and Scripting

Redirect grep output into file !!!!!

Hi, I am writing the following code in command prompt it is working fine. grep ',222,' SAPPCO_20080306.CSV_old > SAPPCO_20080306.CSV_new But the command is not working in the Shell Script... ########################################## #!/bin/sh #... (2 Replies)
Discussion started by: hanu_oracle
2 Replies

10. UNIX for Dummies Questions & Answers

Redirect the Time result to a test file

I need to store process runtime into a file, currently the command i use was: time ls >> abc.txt however, this command store the executed result of ls into the txt file but not the time command result. Anyone know how to store the "time ls" result? Please advise me! Thanks in advance :) (5 Replies)
Discussion started by: mistella
5 Replies
Login or Register to Ask a Question