The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed redirection myle UNIX for Dummies Questions & Answers 3 03-12-2008 04:04 PM
csh stderr redirection jolok Shell Programming and Scripting 0 04-15-2005 07:03 AM
I/O redirection within a coprocess Mugin Shell Programming and Scripting 4 10-21-2003 05:17 AM
Help with redirection Shallon1 High Level Programming 2 12-12-2001 04:35 AM
redirection to tty** with cat zorro UNIX for Dummies Questions & Answers 1 11-02-2001 08:23 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-18-2008
Registered User
 

Join Date: Jan 2008
Posts: 69
redirection

Hi,

The code below works, it's a part of a bash shell script that serve to search a pattern $pattern_da_cercare in the files contained in a directory $directory_iniziale.

Now the proble is:
How can I redirect stderr to a file?
PS: so I want to redirect ALL the errors to a file.

I tryed to learn how to do it, but I haven't understood

Code:
find $directory_iniziale -type f | while read file 
do
  
  awk -v min=$MIN -v max=$MAX -v patt=$pattern_da_cercare '
  BEGIN{RS=" |\n"; patt = "(^|[^A-Za-z0-9])" patt "([^A-Za-z0-9]|$)" }
  $0 ~ patt {n++}
  END {
		if(n >= min && n <= max && n != 0) {print FILENAME " : " n}
  }
  ' "$file"

done
Reply With Quote
Forum Sponsor
  #2  
Old 04-18-2008
Registered User
 

Join Date: Mar 2008
Location: Bay Area California
Posts: 63
try this.....


yourscript 2>&1 > somefile

says take STDERR (2) and redirect to same place as STDOUT (&1)...
Reply With Quote
  #3  
Old 04-18-2008
Registered User
 

Join Date: Jan 2008
Posts: 69
Quote:
Originally Posted by quine View Post
try this.....


yourscript 2>&1 > somefile

says take STDERR (2) and redirect to same place as STDOUT (&1)...
I inserted it in my script, but find still procude output errors on the screen and the error-file is empty

Code:
find $directory_iniziale -type f | while read file 2>&1 > conta_occorrenze_log.txt
do
  
  awk -v min=$MIN -v max=$MAX -v patt=$pattern_da_cercare '
  BEGIN{RS=" |\n"; patt = "(^|[^A-Za-z0-9])" patt "([^A-Za-z0-9]|$)" }
  $0 ~ patt {n++}
  END {
		if(n >= min && n <= max && n != 0) {print FILENAME " : " n}
  }
  ' "$file"

done
Reply With Quote
  #4  
Old 04-18-2008
Registered User
 

Join Date: Jul 2007
Posts: 93
you want to put that on your command line, not within the script!
Reply With Quote
  #5  
Old 04-18-2008
Registered User
 

Join Date: Jan 2008
Posts: 69
Quote:
Originally Posted by denn View Post
you want to put that on your command line, not within the script!
I only don't want that appear any errors on the screen.

Last edited by DNAx86; 04-18-2008 at 08:20 AM.
Reply With Quote
  #6  
Old 04-18-2008
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,022
Code:
find $directory_iniziale -type f 2>/dev/null | ....
Reply With Quote
  #7  
Old 04-18-2008
Registered User
 

Join Date: Jan 2008
Posts: 69
Quote:
Originally Posted by vgersh99 View Post
Code:
find $directory_iniziale -type f 2>/dev/null | ....
So I have to put 2> after every command?

Can I redirect all the errors to a file in all the script?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:58 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0