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.
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.
s/(\sPIC\s+)9(?=\(\d+\)\./ ${1}X/;
sorry
s/(\sPIC\s+)9(?=\(\d+\)\.) /${1}X/;
s/(\sPIC\s+)9(?=\(\d+\)\.)
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;
$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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.