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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
tee vs output redirection confusion c_d UNIX for Dummies Questions & Answers 11 04-02-2009 06:44 AM
Redirection of output to a log file JohnCrump UNIX for Dummies Questions & Answers 8 08-22-2008 05:25 AM
who truncates the output? redirection? tty? Bug? fredy UNIX for Advanced & Expert Users 7 12-10-2006 02:21 AM
Redirection of output (for logging) _Spare_Ribs_ Shell Programming and Scripting 3 12-04-2006 02:17 PM
Standard output and redirection jerardfjay Shell Programming and Scripting 2 06-27-2005 12:03 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-21-2009
cmdup cmdup is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 2
redirection output in two files

I want to redirect output of my script to two logfiles.
I tried this :
./run.sh -c APP | tee >(grep " " > AppLogs.log) >(grep "XYZ" > xyz.log) >dev/null
but this does not solve my purpose because logfile xyz.log remains empty untill i stop my script, i want both files, AppLogs.log and xyz.log, to grow together.
someone plz help me doing this.
  #2 (permalink)  
Old 07-21-2009
anchal_khare anchal_khare is offline
Registered User
  
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 325

Code:
echo "this is log" | tee -a file1 file2

  #3 (permalink)  
Old 07-21-2009
cmdup cmdup is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 2
Quote:
Originally Posted by anchal_khare View Post
Code:
echo "this is log" | tee -a file1 file2
i am using grep to filter data, in this case file1 and file2 will contain same data..
  #4 (permalink)  
Old 07-21-2009
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,915
You could try something like this:


Code:
./run.sh -c APP | 
  awk '/ / { print > "AppLogs.log" }
       /XYZ/ { print > "xyz.log"  }
       '

  #5 (permalink)  
Old 07-21-2009
kshji's Avatar
kshji kshji is offline
Registered User
  
 

Join Date: Jun 2009
Location: Finland
Posts: 236
Previous awk is good and if your need both "grep" can be true in same line, then previous do it. Awk is excellent when you have group of rule and need to make every rule or only some / input record.

This shell example do only one of cases. (case is "multi grep")


Code:
> xyz.log
> AppLogs.log

./run.sh -c APP | while read line
do
        case "$line" in
                *XYZ*) echo "$line" >>  xyz.log ;;
                *" "*)   echo "$line" >> AppLogs.log ;;
        esac
done

Ex. online logfile tracking is easy with this method
tail -f logfile | while read line ...
Reply

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 08:34 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