PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Removing specific lines from a file -with conditions
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Removing specific lines from a file -with conditions

Réponse
 
LinkBack Outils de la discussion
Vieux 24/03/2008, 00h51   #1
musiclover
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Removing specific lines from a file -with conditions

Hi,
I have a huge file having ~500,000 records. I want to remove certain
records satisfying some criteria (that field 3 and 4 both have value
0). I wrote following script, but I am getting errors:

#!/bin/sh
lno=0
while read line
do
lno=`expr $lno + 1`
echo "line read" $lno
annot =`echo $line | cut -f 3 -d " "`
gen = `echo $line | cut -f 4 -d " "`

if [ $annot -eq 0 ]
then
if [ $gen -eq 0 ]
then
echo "delete it"
fi
else
echo $line >> balancedset
fi
done < ./newTrainingset12.dat
-----------------------------------------------#
Errors:
removeoutliers.sh: line 8: annot: command not found
removeoutliers.sh: line 9: gen: command not found
removeoutliers.sh: line 11: [: -eq: unary operator expected


-----
I tried doing the command substitution on the prompt, and it works
there.
could anyone tell me what's wrong here?
Thanks
  Réponse avec citation
Vieux 24/03/2008, 00h54   #2
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing specific lines from a file -with conditions



On 3/23/2008 6:51 PM, musiclover wrote:
> Hi,
> I have a huge file having ~500,000 records. I want to remove certain
> records satisfying some criteria (that field 3 and 4 both have value
> 0).


awk '$3!=0 || $4!=0' file

Ed.

  Réponse avec citation
Vieux 24/03/2008, 02h29   #3
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing specific lines from a file -with conditions

On 2008-03-23, musiclover <oramaster1@gmail.com> wrote:
>
>
> Hi,
> I have a huge file having ~500,000 records. I want to remove certain
> records satisfying some criteria (that field 3 and 4 both have value
> 0). I wrote following script, but I am getting errors:
>
> #!/bin/sh
> lno=0
> while read line
> do
> lno=`expr $lno + 1`
> echo "line read" $lno
> annot =`echo $line | cut -f 3 -d " "`
> gen = `echo $line | cut -f 4 -d " "`
>

When you assign a variable, there should be no space between the
variable name and the = sign.

  Réponse avec citation
Vieux 24/03/2008, 02h41   #4
Maxwell Lol
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing specific lines from a file -with conditions

Ed Morton <morton@lsupcaemnt.com> writes:

> On 3/23/2008 6:51 PM, musiclover wrote:
> > Hi,
> > I have a huge file having ~500,000 records. I want to remove certain
> > records satisfying some criteria (that field 3 and 4 both have value
> > 0).

>
> awk '$3!=0 || $4!=0' file
>
> Ed.


Ed's solution will be much faster. Your solution will be executing 2.5
million programs. Ed's only needs to execute one.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h30.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09566 seconds with 12 queries