Unix Shell - Awk Doubt

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > December 2007 > Awk Doubt





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Awk Doubt
apogeusistemas@gmail.com

2007-12-17, 7:21 pm

Hi:
How could use awk to remove all ocurrences of "Average" in a file ?

cat file

12/01/07 23:45:00 1 1 0 97
12/01/07 23:50:00 0 1 0 98
12/01/07 23:55:00 0 1 0 98
12/01/07 Average 7 2 0 90

cat file | ./script

12/01/07 23:45:00 1 1 0 97
12/01/07 23:50:00 0 1 0 98
12/01/07 23:55:00 0 1 0 98
Glenn Jackman

2007-12-17, 7:21 pm

At 2007-12-17 04:03PM, "apogeusistemas@gmail.com" wrote:
> Hi:
> How could use awk to remove all ocurrences of "Average" in a file ?
>
> cat file
>
> 12/01/07 23:45:00 1 1 0 97
> 12/01/07 23:50:00 0 1 0 98
> 12/01/07 23:55:00 0 1 0 98
> 12/01/07 Average 7 2 0 90
>
> cat file | ./script


awk '/Average/ {next} 1' file

>
> 12/01/07 23:45:00 1 1 0 97
> 12/01/07 23:50:00 0 1 0 98
> 12/01/07 23:55:00 0 1 0 98



--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
Janis Papanagnou

2007-12-17, 7:21 pm

apogeusistemas@gmail.com wrote:
> Hi:
> How could use awk to remove all ocurrences of "Average" in a file ?
>
> cat file
>
> 12/01/07 23:45:00 1 1 0 97
> 12/01/07 23:50:00 0 1 0 98
> 12/01/07 23:55:00 0 1 0 98
> 12/01/07 Average 7 2 0 90
>
> cat file | ./script


Using cat is unnecessary.

./script < file

>
> 12/01/07 23:45:00 1 1 0 97
> 12/01/07 23:50:00 0 1 0 98
> 12/01/07 23:55:00 0 1 0 98


And putting the simple awk command in an own file seems unnecessary.

awk '!/Average/' file

or if you want to be more specific WRT the column number

awk '$2 !~ /Average/' file


Janis
Ed Morton

2007-12-19, 1:23 pm



On 12/17/2007 3:03 PM, apogeusistemas@gmail.com wrote:
> Hi:
> How could use awk to remove all ocurrences of "Average" in a file ?
>
> cat file
>
> 12/01/07 23:45:00 1 1 0 97
> 12/01/07 23:50:00 0 1 0 98
> 12/01/07 23:55:00 0 1 0 98
> 12/01/07 Average 7 2 0 90
>
> cat file | ./script
>
> 12/01/07 23:45:00 1 1 0 97
> 12/01/07 23:50:00 0 1 0 98
> 12/01/07 23:55:00 0 1 0 98


No need for awk:

grep -v Average file

Ed.

mik3l3374@gmail.com

2007-12-20, 7:35 am

On Dec 18, 5:03 am, apogeusiste...@gmail.com wrote:
> Hi:
> How could use awk to remove all ocurrences of "Average" in a file ?
>
> cat file
>
> 12/01/07 23:45:00 1 1 0 97
> 12/01/07 23:50:00 0 1 0 98
> 12/01/07 23:55:00 0 1 0 98
> 12/01/07 Average 7 2 0 90
>
> cat file | ./script
>
> 12/01/07 23:45:00 1 1 0 97
> 12/01/07 23:50:00 0 1 0 98
> 12/01/07 23:55:00 0 1 0 98


not awk though
while read line
do
case $line in
*Average* ) continue ;;
*) echo $line;
esac
done < file
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com