[ale] sed/awk/perl whatever question
scott
scott at sboss.net
Tue Nov 3 15:12:41 EST 2009
Quick and dirty.. no real checking.. I would spend a little more time
on it if I were going to use this in production on a semi-regular
basis over a one-off usage. it works but there is almost no error
checking/handling.
---
#!/usr/bin/perl
#
$|=1;
#
# datamask.pl <maskfile> <logfile>
# <maskfile> = file of the strings to be masked.
# <logfile> = file that you want to be masked.
#
my @strings=();
my @tempout=();
#
open (IFH, "<$ARGV[0]") || die "couldnt read <maskfile>. \n$!";
foreach my $line (<IFH>)
{
chomp $line;
push @strings, $line;
}
close IFH;
open (IFH, "<$ARGV[1]") || die "couldnt read <logfile>. \n$!";
foreach my $line (<IFH>)
{
push @tempout, $line;
}
close IFH;
$tempstring = join("", at tempout);
foreach my $i (@strings)
{
my $ii=$i;
$ii =~ s/[a-zA-Z0-9]/X/g;
$tempstring =~ s/${i}/${ii}/g;
}
open (OFH, ">$ARGV[1].new") || die "cant create $ARGV[1].new file.\n$!";
print OFH $tempstring;
close OFH;
---
On Nov 3, 2009, at 2:40 PM, Asher Vilensky wrote:
> I think that somebody asked the list a similar question recently,
> but I couldn't find it. Here's the deal:
>
> I have two files:
> file1 - contains unique strings:
>
> 123abc
> 234xyz
> 123456
> kljdhs
> etc
>
> file2 is a huge log file with the unique numbers from file1
> appearing in it multiple times. I need a script that for each
> unique string in file1, will replace it in file2 with XXXX. I did
> this on command line, but it didn't work:
>
> for i in `cat file`
> do
> sed -e 's/'"$i"'/XXXX/g' file2 >> file3
> done
>
>
> Or something like that. The problem is that $i was not interpreted
> right. Any advice anybody? I'll take it in sed/awk/perl.
>
> Thanks.
>
> -- Asher
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
More information about the Ale
mailing list