Remove value 0 from file contents

Remove value 0 from file contents

Post by Frank Kuijt » Sat, 03 Feb 1996 04:00:00



Hello all,

I've got the following problem. I want to remove all lines with the value 0
from a file. However I want to retain values like 10, 101 etc.

Example :
In a file I have the these lines

  10 Rijen niet geladen
    0 Rijen niet geladen
  12 Rijen niet geladen
  ...
  ...
  etc

I want to remove all lines saying   0 Rijen niet geladen.

If I try something like
 awk '{print $0 }' file1 |grep -v 0 > file2
the line saying   10 Rijen niet geladen  is also removed.

Does someone know a solution for this problem.
If so, please provide some sample code.

Thanks in advance.

Frank Kuijten

 
 
 

Remove value 0 from file contents

Post by Bill Zissimopoulo » Sun, 04 Feb 1996 04:00:00


[snip]
Quote:> I've got the following problem. I want to remove all lines with the value 0
> from a file. However I want to retain values like 10, 101 etc.

> Example :
> In a file I have the these lines

>   10 Rijen niet geladen
>     0 Rijen niet geladen
>   12 Rijen niet geladen
>   ...
>   ...
>   etc

> I want to remove all lines saying   0 Rijen niet geladen.

[snip]

awk '$1 != 0'

--


http://www-dept.cs.ucl.ac.uk/students/B.Zissimopoulos/

 
 
 

Remove value 0 from file contents

Post by walter brisco » Sun, 04 Feb 1996 04:00:00



> I've got the following problem. I want to remove all lines with the value 0
> from a file. However I want to retain values like 10, 101 etc.

> Example :
> In a file I have the these lines

>   10 Rijen niet geladen
>     0 Rijen niet geladen
>   12 Rijen niet geladen
>   ...
>   ...
>   etc

> I want to remove all lines saying   0 Rijen niet geladen.

Assuming that 'lines with the value 0' means 'lines in which the first
non-space character is 0' something like `sed '/^ *0/d' <file>` should
just about hit the spot. i.e. Find those lines which start with space
zero or more times and a zero and remove those lines.
`sed '/^ 0*0*[^1-9]/d' is more like "Find those lines which start with
space zero or more times, at least one occurrence of the character zero and
a character which is not a digit other than zero and remove those lines.
[Regular expressions are wonderfully succinct. English is horribly
verbose in comparison.] I am sorry I have not tested these thoughts; my
documentation and unix machine are at the office.
--
walter briscoe
 
 
 

Remove value 0 from file contents

Post by Ian Park » Sun, 04 Feb 1996 04:00:00


:   10 Rijen niet geladen
:     0 Rijen niet geladen
:   12 Rijen niet geladen

:  awk '{print $0 }' file1 |grep -v 0 > file2

If you must use awk :

awk '$1 != 0 {print}' < <your file>

FYI grep will match the 0 in any position in a line, which is why the value of
10 is getting junked.

IAP

 
 
 

Remove value 0 from file contents

Post by Rock N Ro » Mon, 05 Feb 1996 04:00:00


grep -v " 0" file1 > file2

: Hello all,

: I've got the following problem. I want to remove all lines with the value 0
: from a file. However I want to retain values like 10, 101 etc.

: Example :
: In a file I have the these lines

:   10 Rijen niet geladen
:     0 Rijen niet geladen
:   12 Rijen niet geladen
:   ...
:   ...
:   etc

: I want to remove all lines saying   0 Rijen niet geladen.

: If I try something like
:  awk '{print $0 }' file1 |grep -v 0 > file2
: the line saying   10 Rijen niet geladen  is also removed.

: Does someone know a solution for this problem.
: If so, please provide some sample code.

: Thanks in advance.

: Frank Kuijten

--
                                 ---\    ---
                                 |   \   |R|
                                 |R|\ \  |O|
                                 |O| \ \ |L|
                                 |C|  \ \|L|
                                 |K|   \   |
                                 ---    \---

 
 
 

Remove value 0 from file contents

Post by Mikel Douce » Mon, 05 Feb 1996 04:00:00



Quote:> :   10 Rijen niet geladen
> :     0 Rijen niet geladen
> :   12 Rijen niet geladen

> :  awk '{print $0 }' file1 |grep -v 0 > file2

You can you 'grep' directly:

  grep '^ *0' <FILE>

-------------------------------------------------------------------------------
| Mikel Doucet, eng                  |   ATS Aerospace Inc.                   |

| Tel : +1 (514) 441-6744 (ext 291)  |   St-Bruno, Quebec (Canada)            |
| Fax : +1 (514) 441-6789            |   J3V 6B8                              |
-------------------------------------------------------------------------------

 
 
 

Remove value 0 from file contents

Post by Jorma F. Korkiakos » Tue, 06 Feb 1996 04:00:00



>    awk '{print $0 }' file1 |grep -v 0 > file2

        How about:

                grep -v -w 0 < file1 > file2

--
                        And George can't dance.

 
 
 

Remove value 0 from file contents

Post by Malcolm Murp » Tue, 06 Feb 1996 04:00:00


:> Example :
:> In a file I have the these lines

:>   10 Rijen niet geladen
:>     0 Rijen niet geladen
:>   12 Rijen niet geladen
:>   ...
:>   ...
:>   etc
:> I want to remove all lines saying   0 Rijen niet geladen.
Well, if your input is in exactly this form (i.e. the number is the
first field) then this will work:

  awk '$1!=0 {print $0}' foo

where foo is your file.

:> If I try something like
:>  awk '{print $0 }' file1 |grep -v 0 > file2
You could write this as:

  grep -v 0 file1 > file2

Your use of awk (to achieve the same thing as cat!) is unnecessary.

:> the line saying   10 Rijen niet geladen  is also removed.
Because grep doesn't consider there to be any whitespace around the 0 in
your command line.  You could quote it:

  grep -v ' 0 ' file1 > file2.

Note this doesn't have the restriction of the awk version that the
number is in the first field.  

--

        \/  http://kingdom.maths.bris.ac.uk/~MurphyM

 
 
 

1. Setting a local variable's value to the content of a file.

I'm trying to write a script and in it I need to use a local variable that
I define and I need to set the value of this variable to the value of the
first line of a file.

I can get the first line of a file by typing:

head -1 filename

...and  it outputs to my screen the first line of the file.  But how do I
assign that output to the value of a variable?

I've tried things like:

head -1 filename > $variablename

set variablename < head -1 filename

I've also tried this:

export variablename=`head -1 filename`

...but I get a permission denied error and the man pages show nothing for
"export".

None of the above works.  Any ideas?  (BTW - we are running DG/UX on a Data
General AViiON.)

Any help is greatly appreciated!  Thanks!

--
Matt Brennan
SQL*Tools Specialist
GERS Retail Systems
9725-C Scranton Road
San Diego, California 92121
1-800-854-2263

2. openssh and solaris 2.5.1 - weird 'password-less' key exchange problem

3. Remove new lines from tnsnames.ora file to analyse the content

4. userland ppp: special options for user

5. Removing funny files (Re: how do i remove a file with a ~ in it ????)

6. Q:lpNet vsz growing ?

7. ununcompression issue during installation script

8. Can't remove a file called "---remove-files"

9. Stripping out value from file, value is a variable though.

10. Find numeric value in xml file, recalculate, and replace old value

11. 2.5.40 kbuild bug: mrproper removes files it shouldn't remove