Thank you for all the responses and interesting insights.

 

After some experimentation, I have come up with the following code snippet which pads the first “column” numbers with zeros (0’s) instead of white spaces:

 

        if ($section_1_line =~ /^\s*\d+/) {

 

          my $regex_search  ='^\s';

          my $regex_replace = '0';

          for (my $icnt = 1 ; $icnt <= 5 ; ++$icnt) {

            if ($section_1_line =~ /$regex_search\d/) {

              $section_1_line =~ s/$regex_search/$regex_replace/;

              last;

            } else {

              $regex_search .= '\s';

              $regex_replace .= '0';

            } # if

          }  # for

 

          …

 

         } # if

 

This might not be the most elegant way to achieve my goal, but it works for now.  This also maintains the original file size, which is not that important.  If anyone can see a better way, please feel free to respond.

 

Again, thank you everyone.

 

 

Sui

 

 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Sui Ming Louie
Sent:
Friday, January 30, 2004 5:08 PM
To: [EMAIL PROTECTED]
Subject: Regex Needed

 

I have text data files which have “first column” numbers that are preceded by spaces (or tabs).  When I import these files into Excel, the first column numbers are shifted to column B instead of being in column A in Excel.  Is there a way (using regex) to change the files without altering the size of the original files such that they will import properly in Excel?

 

Example file excerpt:

 

7         (other information follows)

8         more stuff

9         more info

10     some more

11     other stuff

12      

16

 

 

Thank you in advance.

 

 

Regards,

 

Sui Ming Louie

FTL Design Engineering Studio

www.ftlstudio.com

 

 

Reply via email to