The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
how to spool a unix file kripssmart Shell Programming and Scripting 2 06-18-2008 04:35 AM
Can I delete the file var/spool/mail/news? dennisheazle UNIX for Dummies Questions & Answers 3 04-08-2008 11:12 PM
code to FTP the spool file from Sqlplus to the unix server. vprevin Shell Programming and Scripting 0 10-31-2007 02:48 AM
grep error Dave724001 UNIX for Dummies Questions & Answers 2 11-07-2006 06:48 AM
Increase width of Spool file handynas UNIX for Dummies Questions & Answers 2 11-20-2001 09:24 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-18-2008
ran16 ran16 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 16
grep spool file error

Hi,
I am trying to do this
For i in *.txt
do
sed 'some pattern checking' $i
done
>file

These text files are spool files.And when i find error in these spool files I want to append the text file contents to error.log file.
Or is there any option that I do this sed for only files that does not contain errors?
Can some one tell me how can i do this please..

Last edited by ran16; 06-18-2008 at 08:44 AM..
  #2 (permalink)  
Old 06-18-2008
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
this would give you a list of files that contain the pattern you are looking for:
Code:
grep -l 'pattern_to_check' * | sort | uniq
so you could do:
Code:
for file in `grep -l 'pattern_to_check' * | sort | uniq`
do
    cat $file  >> error.log
done
  #3 (permalink)  
Old 06-18-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
I don't think you need the sort | uniq because grep will only print each file name once. In any event, the purpose of cat is to concatenate multiple files, so you really don't need the loop either.

Code:
cat `grep -l 'pattern_to_check' *.txt` >>error.log
  #4 (permalink)  
Old 06-18-2008
ran16 ran16 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 16
It worked

Thanks Yogesh it worked...
  #5 (permalink)  
Old 06-18-2008
ran16 ran16 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 16
grep excluding pattern

Hi,
Please tell me how I can grep files which does not have given pattern.

Thanks
  #6 (permalink)  
Old 06-18-2008
uttamhoode uttamhoode is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 18
hi ran16,
use -v option in grep
Thanks and Regards,
uttam hoode
  #7 (permalink)  
Old 06-18-2008
ran16 ran16 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 16
If I use like grep -v 'ERROR' *.txt then I get lines also from the text files which do not have ERROR pattern
I want to grep only files that do not have the pattern

I even used 'grep -r exclude' option but some how syntax is wrong I think so.

Please tell me the exact command
Closed Thread

Bookmarks

Tags
grep, sort

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 05:27 AM.


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