Hello Muthukumar,
 
My problem is that I would like to extract a part of a variable (which is a 
filename stored in this variable.
The part I want to extract is only composed of characters in uppercase.
For example if I have this file list:
 
-rw-r--r--   1 oracle   dba        13659 Oct  5 01:04 
rman_APPEOS-archivelog-05-10-05-0100.log
-rw-r--r--   1 oracle   dba        12778 Oct  5 01:49 
rman_NDOS-archivelog-05-10-05-0145.log
-rw-r--r--   1 oracle   dba        26231 Oct  5 01:55 
rman_CAREOFFICE-archivelog-05-10-05-0130.log
-rw-r--r--   1 oracle   dba        14429 Oct  5 02:07 
rman_IXOS-archivelog-05-10-05-0200.log
-rw-r--r--   1 oracle   dba         3985 Oct  5 02:32 
rman_TEST-archivelog-05-10-05-0230.log
-rw-r--r--   1 oracle   dba        16788 Oct  5 03:06 
rman_ORAMGT-archivelog-05-10-05-0300.log
-rw-r--r--   1 oracle   dba         1991 Oct  5 03:32 
rman_DIVERS-archivelog-05-10-05-0330.lo
 
 
For each file i want only the uppercase part. Like "APPEOS", "NDOS", 
"CAREOFFICE"...
Then I want to store this part in a variable.
 
Below is my script:
---------------------------
my @SOURCE_FILES = glob "/u01/oracle/local/logs/*.log" ;
...
foreach ( @SOURCE_FILES )
{
  if ( -M $_ < 1 )
  {
    my $name = $_ ;
    my $basename = basename $name ;
    my $ORACLE_SID = "" ;
    ( $ORACLE_SID ) = ( $basename =~ /[A-Z]*/ ) ; <-- I tried that but that 
won't work ...
    #print  "Nom du fichier: $_\n" ;
    print  "Nom du fichier: $basename\n" ;
    print "Instance Oracle: $ORACLE_SID\n" ;
  }
}
 
    ( $ORACLE_SID ) = ( $basename =~ /[A-Z]*/ ) ; <-- I tried that but that 
won't work ...
 
 
output is:
-------------
[EMAIL PROTECTED] [ORAMGT] # ./ScanRMANLogs.pl 
Nom du fichier: rman_APPEOS-archivelog-05-10-05-0100.log
Instance Oracle: 1
Nom du fichier: rman_CAREOFFICE-archivelog-05-10-05-0130.log
Instance Oracle: 1
Nom du fichier: rman_DIVERS-archivelog-05-10-05-0330.log
Instance Oracle: 1
Nom du fichier: rman_IXOS-archivelog-05-10-05-0200.log
Instance Oracle: 1
Nom du fichier: rman_NDOS-archivelog-05-10-05-0145.log
Instance Oracle: 1
Nom du fichier: rman_ORAMGT-archivelog-05-10-05-0300.log
Instance Oracle: 1
Nom du fichier: rman_TEST-archivelog-05-10-05-0230.log
Instance Oracle: 1
[EMAIL PROTECTED] [ORAMGT] # 

I would like to have something like:
--------------------------------------------------
Nom du fichier: rman_APPEOS-archivelog-05-10-05-0100.log
Instance Oracle: APPEOS
 
Thanks for your help !
 
 
Jean
 

-----Message d'origine-----
De : Muthukumar [mailto:[EMAIL PROTECTED]
Envoyé : mercredi, 5. octobre 2005 12:21
À : BERTHOLD Jean
Cc : beginners@perl.org
Objet : Re: Extracting Upper case letter from a variable


You have to try as,
 
$var=~operation;
 
Example:
 
# perl -e '$var="HIbyeok";$var=~s/HI/OK/;printf $var . "\n";'
OKbyeok
 
-Muthu
 
On 10/5/05, BERTHOLD Jean < [EMAIL PROTECTED]> wrote: 

Hello,

I try to replace my old shells scripts with perl ...

Can you tell me how to extract a substring in upper case from a variable and 
assign that substring to a variable ? 

Do I need to proceed character by character  using a loop to recognize each 
upper case or can I do that by using regular expression ?

In shell scripts, of course I use awk. Then I cannot find it's equivalent in 
perl. 

For example, I need to extract the word "DIVERS" from the filename 
"rman_DIVERS-archivelog-29-09-05-0330.log" and assign this word to a variable.

In shell script this is done by something like that: 
--------------------------------------------------------------------------
gauche=`ls rman_DIVERS-archivelog-29-09-05-0330.log | awk -F- '{print $1}'`
ORACLE_SID=`echo $gauche | awk -F_ '{print $2}'`

And in Perl, can you help me ? 

Thanks and have a nice day !

E O S   H  o  l  d  i  n  g

Jean Berthold

Administrateur Unix & Oracle

Unité Gestion de l'infrastructure

Team Systèmes

Ch. de Mornex 10

Tel +41 21 341 24 58

Fax +41 21 341 20 46

[EMAIL PROTECTED]





Reply via email to