Link to home
Start Free TrialLog in
Avatar of jdg3
jdg3

asked on

Need a Regular Expression.

I have thousands of COBOL Copybooks where I need to make modifications to various number of PICS.  I am looking for a regular expression that will replace the following '9' to an 'X'  


From:

~PIC~9(N).

to

~PIC~X(N).


where the '~' is a VARIABLE number of spaces, and where 'N' is a VARIABLE number of digits. The period '.' at the end of the line is required on the line.  The parentheses '( )' are also required as part of the PIC line.

Finally,  I do not want to modify any PIC 9's that are COMP or COMP3.  For instance, the following is not a candidate for modification:

~PIC~9(7)~COMP3.

I am new to regular expressions, and do not know how to handle the parentheses and periods, inasmuch as they are actually part of the expression.  The type of regular expression can be Perl or Unix.

Thanks in advance.
Avatar of ozo
ozo
Flag of United States of America image

s/(\sPIC\s+)9(?=\(\d+\)\./${1}X/;
sorry
 s/(\sPIC\s+)9(?=\(\d+\)\.)/${1}X/;
this pel script will replace 9(04) to X(04) if the usage is not comp or comp3

$d = "01 ar    pic    9(04) usage is comp";
if($d =~/\S+\s+9\(\d+\).*comp/)
{
   #do nothin;
}
else
{
   if($d =~/\S+\s+9\(\d+\)/)
   {
      #print "helloo";
      $d =~s/9\(/X\(/;
   }
}
print $d;
SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial