In PERL script
I have few files named theme1.htm,theme2.htm,theme3.htm and so on.
now I need to write perl code to split the the filename and store only that particular digit.
Example
--------------
filename is theme1.htm
output should be 1
another example
---------------
filename is theme3.htm
output should be 3
Could you please help me in writing the perl code.
Thanks in advance....
$ echo "theme3.htm" | perl -lane 's/theme(\d+).htm/$1/;print $_'
3
$ echo "theme150.htm" | perl -lane 's/theme(\d+).htm/$1/;print $_'
150
1 Like
Another example (Perl)
$var = "theme1.htm";
From the above variable 1 has to be seperated and should be stored
in another variable. i.e., the output should be 1
bmk
August 2, 2012, 2:19am
4
In unix..
try like...
echo "theme1.htm" | tr -dc '[0-9]'
1 Like
#!/bin/perl
$var="theme108.htm";
$var=~m/theme(\d+).htm/;
$anothervar=$1;
print $anothervar;
1 Like
Many thanks kamaraj.
I am writing the script in perl and here the filename is assigned to a variable.
So Could you please make use of variable which contains the filename and then split it.
$filename = "theme1.htm";
Now I need to print only 1.
---------- Post updated at 01:23 AM ---------- Previous update was at 01:20 AM ----------
Many thanks kamaraj ... It worked...
ThanQ bmk...