grep spool file error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep spool file error
# 8  
Old 06-18-2008
grep -v will find any file which contains a line which doesn't match, so that's not what you want.

Code:
for f in *.txt; do
  grep 'pattern' "$f" >/dev/null && continue
  echo $f
done |
xargs cat >nonmatching.txt

Just take out the pipeline to xargs at the end if you just want to list the file names.
# 9  
Old 06-18-2008
Era,
my requirement is

for f in 'grep 'pattern' "$f" >/dev/null .....(need syntax)
Do some sed or awk
done

That is I want to do a 'for loop and do some awk' for files
which does not contain the pattern.
# 10  
Old 06-18-2008
The syntax from above should work. The continue will break out of the loop for those files which have a match; if you get past that line, $f contains the name of a file which does not contain a match. (Oops, should properly double quote "$f" in case the file name contains special characters, always.)

Code:
for f in *.txt; do
  grep 'pattern' "$f" >/dev/null && continue
  do some sed or awk with "$f"
done

Quite possibly you could "do some sed or awk" with xargs as per what I posted before, for improved efficiency.
# 11  
Old 06-18-2008
still not solved

Era,
I have tried your code but still awk is done for all the files including the files with pattern
I doubt after awk when i give awk ' ' $i
it is taking file from the *.txt instead of the set we got from grep.

Last edited by ran16; 06-18-2008 at 01:32 PM..
# 12  
Old 06-18-2008
I'm not sure I understand you. Here's a quick demonstration of what you should be seeing.

Code:
vnix$ for f in foo food bar barn ; do echo This is $f >$f; done
vnix$ ls
bar  barn  foo  food
vnix$ nl foo
     1  This is foo
vnix$ for f in *; do
>   grep foo "$f" >/dev/null && continue
>   nl "$f"
> done
     1  This is bar
     1  This is barn

As you can see, nl runs on each file which does not match the pattern foo, one at a time in turn. As far as I can understand, this is what you want to do as well (but with awk instead of nl, which I just used as a simple example here).

Last edited by era; 06-18-2008 at 01:42 PM.. Reason: Add "This is" to file contents, to hopefully make it clearer
# 13  
Old 06-18-2008
Thanks

Era
Thank you for your patience in answering me.
My problem got solved.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Order of data in Spool File

Hello, I have a shell script through which I am executing .sql file and spooling the result of Query from .sql . I want to spool the result in ascending order. Is there any parameter to be set to print result in ascending or descending order. Thanks in advance. (4 Replies)
Discussion started by: Aparna.N
4 Replies

2. Shell Programming and Scripting

Spool file requirement

Hi, I have a requirement of Connecting to sqlplus from unix Execute the package. The output of package is stored in a table Need to query the table and move to txt file. The problem iam facing is, when I try to spool the file. I get the sql query also along with the output.... (6 Replies)
Discussion started by: Shanmugapriya D
6 Replies

3. Shell Programming and Scripting

Spool Data in a file

Hello, I am trying to spool data from database into a file on solaris through ksh. Data is getting fetched but the problem is record is getting split in to multiple lines. excerpt from sql is whenever sqlerror exit 1; set define on set echo off set feed off set head off set... (1 Reply)
Discussion started by: abhi1988sri
1 Replies

4. Shell Programming and Scripting

Spool file with .txt extension

Hi I am logging into sql using script. sqlplus ima/ima@test <<! spool /opt/tt/spoolfile.txt @sql.sql spool off. now i am getting a spool file named spoolfile.txt.lst i want it to be only spoolfile.txt I am working on solaris Please help (6 Replies)
Discussion started by: ankurk
6 Replies

5. Shell Programming and Scripting

spool to file in ksh

hi all, am trying to write a ksh script which will take a username, password, db instance as input arguments and login to the database using sqlplus and select some data via sql and spool to a file. problem is that i am using "sqlplus -s" in order to hide the username/password and it doesnt... (8 Replies)
Discussion started by: cesarNZ
8 Replies

6. Shell Programming and Scripting

Problem in spool file

Hi, Iam a newbie. When I give the below query at SQL prompt. SQL> select col1||'`ß`'||col2 from tablename where rownum<2; 1-J7WGX`ß`1-7OKC-23 Iam getting ß within appostropies...... If I remove appostropies and give the query it is throwing an error. If I give the same query in spool as... (1 Reply)
Discussion started by: kknayak
1 Replies

7. AIX

Spool data file

Dear Gurus, Tried searching for some clues in this forum but dont seem to be able to find my answer. :confused: Anyway i have a quick question: Today I have produced a messages generated from a application and placed them on the print queue. Before this I had stopped the printer queue, so... (2 Replies)
Discussion started by: lweegp
2 Replies

8. UNIX for Dummies Questions & Answers

SQLPlus spool file

HI Have some problem with spooling out some relatively large number of records (~2-3 mil) Small table - OK though. Getting error: SP2 0308: cannot close spool file. Any thoughts? sqlplus -s user/pwd << EOF set term off set head off set trims on set pages 0 set... (1 Reply)
Discussion started by: Leo_NN
1 Replies

9. Shell Programming and Scripting

how to spool a unix file

hi, can anyone help me by saying how can i spool a unix file.. do we need to specify the pathname as such to spool the file .. right now, i tried giving like spool filename in the sql prompt.. but its not giving me the required output even if i can see that the command is being executed.. ... (2 Replies)
Discussion started by: kripssmart
2 Replies

10. UNIX for Dummies Questions & Answers

Increase width of Spool file

Hi All This may not be entirely Unix related but I'll just have to try my luck and see if you know how to do this: I need to spool the results of my SQL query into a file but as there are too many fields in the query the resultant spool file put the last few fields on the next line. May I... (2 Replies)
Discussion started by: handynas
2 Replies
Login or Register to Ask a Question