awk for a cleaner approach

awk for a cleaner approach

Post by ab » Sun, 07 May 2006 08:38:38



is there a way to

awk  '/look_for_lines_with_this/' somefile.txt

but instead of  printing only lines with  the pattern
print only the lines that do not have the pattern?

currently useing script , but it does  alot of i/o
and take  awhile ,
  current use
   for a in variable
     do
      grep -v $a  fileA.txt > fileB.txt
      cp fileB.txt fileA.txt
     done

a better way would be appreciated
using bash  on  a Sol 10  intel box.

thks ....ab

 
 
 

awk for a cleaner approach

Post by Xicheng Ji » Sun, 07 May 2006 08:46:39



> is there a way to

=> awk  '/look_for_lines_with_this/' somefile.txt
=> but instead of  printing only lines with  the pattern
=> print only the lines that do not have the pattern?

awk  '!/look_for_lines_with_this/' somefile.txt

Quote:> currently useing script , but it does  alot of i/o
> and take  awhile ,
>   current use
>    for a in variable
>      do
>       grep -v $a  fileA.txt > fileB.txt
>       cp fileB.txt fileA.txt
>      done

> a better way would be appreciated
> using bash  on  a Sol 10  intel box.

> thks ....ab


 
 
 

awk for a cleaner approach

Post by Bill Seiver » Sun, 07 May 2006 15:08:42



> is there a way to

> awk  '/look_for_lines_with_this/' somefile.txt

> but instead of  printing only lines with  the pattern
> print only the lines that do not have the pattern?

> currently useing script , but it does  alot of i/o
> and take  awhile ,
>  current use
>   for a in variable
>     do
>      grep -v $a  fileA.txt > fileB.txt
>      cp fileB.txt fileA.txt
>     done

> a better way would be appreciated
> using bash  on  a Sol 10  intel box.

> thks ....ab

grep -v "pattern" somefile.txt

Bill Seivert

 
 
 

awk for a cleaner approach

Post by John » Sun, 07 May 2006 15:35:13



> is there a way to

> awk  '/look_for_lines_with_this/' somefile.txt

> but instead of  printing only lines with  the pattern
> print only the lines that do not have the pattern?

> currently useing script , but it does  alot of i/o
> and take  awhile ,
>   current use
>    for a in variable
>      do
>       grep -v $a  fileA.txt > fileB.txt
>       cp fileB.txt fileA.txt
>      done

awk ' ! /pattern/ { print }'

But forget awk because it will be slower than grep.

First, you have more than one pattern (in a loop).
Put them all in a file (patternfile) and use
    grep -vf patternfile fileA.txt

Second, if the patterns are really fixed strings
(rather than regular expressions) then use fgrep
or grep -F
    grep -Fvf patternfile fileA.txt

--
John.

 
 
 

awk for a cleaner approach

Post by Robert Bono » Thu, 11 May 2006 07:45:20




>is there a way to

>awk  '/look_for_lines_with_this/' somefile.txt

>but instead of  printing only lines with  the pattern
>print only the lines that do not have the pattern?

>currently useing script , but it does  alot of i/o
>and take  awhile ,
>  current use
>   for a in variable
>     do
>      grep -v $a  fileA.txt > fileB.txt
>      cp fileB.txt fileA.txt
>     done

>a better way would be appreciated
>using bash  on  a Sol 10  intel box.

One (state-machine-like) possibility --
awk '/look_for_lines_with_this1/ {continue;}
     /look_for_lines_with_this2/ {continue;}
     /look_for_lines_with_this3/ {continue;}
     /look_for_lines_with_this4/ {continue;}
     /look_for_lines_with_this5/ {continue;}
           .
           .
           .
     {print;}' somefile.txt

for performance reasons, order the patterns with the most-frequently-occurring
first.

 
 
 

1. CD-ROM cleaners

Hi,

I was wondering if anyone had any pointers for using those CD-ROM
cleaning disks. I was taking a look at them and they all seem to require
running some Win program to start the process. Does anyone have any
experience/tips/pointers about this subject?

2. TV HELP, pls... compiling problems

3. Solaris 2.4 bug cleaner?

4. PowerBook 3400c, MKLinux and Serial

5. Cleaner Fortunes

6. Is anyone else disgusted with how slow Solaris patches are ?

7. Intelligent /tmp cleaner

8. masquerading appletalk?

9. Cleaner Fortunes

10. tape cleaners and certifiers

11. Getting dip to die a cleaner death

12. Cleaner Fortunes

13. Looking for a cleaner solution