help with a script change
am 08.01.2008 00:20:20 von AB
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
Re: help with a script change
am 08.01.2008 04:49:57 von Barry Margolin
In article
<3ac96394-47be-43b2-8e13-03ad81f370b8@r60g2000hsc.googlegroups.com>,
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 .
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 ***
Re: help with a script change
am 08.01.2008 05:32:48 von Ed Morton
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.