Question: During the startup of a Linux AMI, I would like to download some data (like the sun java libraries and some proprietary software) from an S3 bucket while initializing my EC2 connection. I notice that one way to do this is to use s3cmd. BUT, how do I get the configuration file for s3cmd .s3cfg from S3?

Also, let me also know if there is a better way to connect to S3 storage during init.

Thanks!

Answer: 
Why not do it entirely in perl, rather than using awk? You should be able open the file, read in each line and print it out if the regex matches. Regular expressions are one of perls best strengths, why not take advantage of them directly rather than trying to call awk?

The only advantage I see to using awk is that you would have to manually list all of the \*\_Codes.txt files, but that shouldn't be too difficult in perl.

The easiest way to do it in perl, assuming you have a line of text, is simply to run the regex 3 times, one for each portion you're trying to match. For exmaple, if you want to match `204`, `test` and `leg` you should be able to do

```
if (($line =~ m/ 204/i) && ($line =~ m/ test/i) && ($line =~ m/ leg/i)){
    print $line;
}

```
Pure Perl solution, including splitting `$code_search`, globbing the filenames, and matching the patterns only at the beginnings of words:

```
use List::MoreUtils qw{ all };

my @words = ($code_search =~ m/\S+/g);

for my $fn (glob('*_Codes.txt')) {
    open my $f, '<', $fn || die "Can't open: $!";

    while (defined(my $line = <$f>)) {
        if (all { $line =~ m{\b\Q$_\E}is } @words) { print $line }
    }

    close $f;
}

```

If you don't want to depend on List::MoreUtils, then change the 'if' to:

```
        if (!grep { $line !~ m{\b\Q$_\E}is } @words) { print $line }

```

— a bit harder to read, but only uses perl builtins.