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..
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.
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.
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.)
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.
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.
I'm not sure I understand you. Here's a quick demonstration of what you should be seeing.
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).