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 > with a script change
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

with a script change

Réponse
 
LinkBack Outils de la discussion
Vieux 07/01/2008, 23h20   #1
ab
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut with a script change


Original post from this group in early 2007

1 ) Have a file where each line is numbered

currently set a variable to the line numbers that i would
like to remove from the file .

then remove the line from the file by
for a in $variable
do
grep -v'^'$a' :' file.txt > temp.txt
cp temp.txt file.txt
done
this has been working fine ; however now that the file is
growing this method is not very efficent ( slooooow ); file is 40
to 50 thousand lines in length and often there are 15 to 20
thousand lines that i would like to remove .

using solaris 10 intel version .
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++
+
2) from this group John provided an excellent solution

perl -ne'BEGIN { ( $a = shift ) =~ s/\s+/|/g } /^($a) :/ || print'
"$variable"
file.txt > temp.txt

++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++
New issue

now with the $variable set to the lines numbers I'd like to keep
from a large file
is it possible to to use something similar to the above ? this time
to move the
lines of interest to the temp.txt file

tried to alter the perl command above without success .

++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++

the perl script in 2 above is very fast , and would like
something similar if possible
(similar in that it could be placed in a script ); is there possibly
a means to do this with awk
that would be quicker than the grep loop indicated in 1

thks.....ab




  Réponse avec citation
Vieux 08/01/2008, 03h49   #2
Barry Margolin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with a script change

In article
<3ac96394-47be-43b2-8e13-03ad81f370b8@r60g2000hsc.googlegroups.com>,
ab <spencedr@gmail.com> wrote:

> Original post from this group in early 2007
>
> 1 ) Have a file where each line is numbered
>
> currently set a variable to the line numbers that i would
> like to remove from the file .
>
> then remove the line from the file by
> for a in $variable
> do
> grep -v'^'$a' :' file.txt > temp.txt
> cp temp.txt file.txt
> done
> this has been working fine ; however now that the file is
> growing this method is not very efficent ( slooooow ); file is 40
> to 50 thousand lines in length and often there are 15 to 20
> thousand lines that i would like to remove .


Use egrep, and set $variable to line1|line2|line3. Then do:

egrep -v "^($variable) :" file.txt > temp.txt

>
> using solaris 10 intel version .
> ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++
> +
> 2) from this group John provided an excellent solution
>
> perl -ne'BEGIN { ( $a = shift ) =~ s/\s+/|/g } /^($a) :/ || print'
> "$variable"
> file.txt > temp.txt
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++
> New issue
>
> now with the $variable set to the lines numbers I'd like to keep
> from a large file
> is it possible to to use something similar to the above ? this time
> to move the
> lines of interest to the temp.txt file
>
> tried to alter the perl command above without success .


Change || to &&.

>
> ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
>
> the perl script in 2 above is very fast , and would like
> something similar if possible
> (similar in that it could be placed in a script ); is there possibly
> a means to do this with awk
> that would be quicker than the grep loop indicated in 1


Use egrep, like I said above. It supports alternation in regexps, just
like perl and awk.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
  Réponse avec citation
Vieux 08/01/2008, 04h32   #3
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with a script change

ab wrote:

> Original post from this group in early 2007
>
> 1 ) Have a file where each line is numbered
>
> currently set a variable to the line numbers that i would
> like to remove from the file .
>
> then remove the line from the file by
> for a in $variable
> do
> grep -v'^'$a' :' file.txt > temp.txt
> cp temp.txt file.txt
> done
> this has been working fine ; however now that the file is
> growing this method is not very efficent ( slooooow ); file is 40
> to 50 thousand lines in length and often there are 15 to 20
> thousand lines that i would like to remove .


awk -v s="$variable" 'BEGIN{c=split(s,t);for(i=1;i<=c;i++)a[t[i]]}
!($1 in a)' file.txt > temp.txt && mv temp.txt file.text

> using solaris 10 intel version .
> ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++
> +
> 2) from this group John provided an excellent solution
>
> perl -ne'BEGIN { ( $a = shift ) =~ s/\s+/|/g } /^($a) :/ || print'
> "$variable"
> file.txt > temp.txt
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++
> New issue
>
> now with the $variable set to the lines numbers I'd like to keep
> from a large file
> is it possible to to use something similar to the above ? this time
> to move the
> lines of interest to the temp.txt file


awk -v s="$variable" 'BEGIN{c=split(s,t);for(i=1;i<=c;i++)a[t[i]]}
($1 in a)' file.txt > temp.txt

> tried to alter the perl command above without success .
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
>
> the perl script in 2 above is very fast , and would like
> something similar if possible
> (similar in that it could be placed in a script ); is there possibly
> a means to do this with awk
> that would be quicker than the grep loop indicated in 1
>
> thks.....ab


Regards,

Ed.
  Réponse avec citation
Vieux 09/01/2008, 22h54   #4
ab
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with a script change


thks egrep solution worked fine once variable up correctly

the && instead of || was great and simple to implement .

tried the awk but resulted in core dump tried
tried default and /usr/xpg4/bin/awk

Barry / Ed thank you for the feed back ....ab

  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 02h35.


É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
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10935 seconds with 12 queries