- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Perl conditions HELP
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2005 08:15 PM
тАО11-13-2005 08:15 PM
Perl conditions HELP
Below is line part of my script:
export Var=$(awk -F "," '/DIFFLOTID/ {print $2}' $FILE)
$perl/perl -e '$PerlVar=$ENV{Var};
$PerlVar=~ m/^[0-9][0-9]*[\.[0-9][0-9]*]{0,1}$/g;
if (pos($PerlVar)) {system("'$scrptpath'/parset2xml -t '$FILE'");system("'$ExePath'/rm '$FILE'");else {system("'$ExePath'/mv -f '$FILE' '$temp'");'
The Var variable will get the DIFFLOTID, then it will be check if it is purely numeric. If it is numeric, then it will call parset2xml program and then remove the file to the system. If the DIFFLOTID is not purely numeric, it will move the file to a temp directory.
I dont know what is wrong with the script lines above.
Maximum points for all correct answers.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2005 08:20 PM
тАО11-13-2005 08:20 PM
Re: Perl conditions HELP
if [ "$(echo $MYVAR | tr -d '[:digit:]')" = "" ]
then
echo "All digits"
else
echo "$MYVAR has non-digits"
fi
or
typeset newvar=$(var) 2>/dev/null
if [[ $? ├в eq 0 ]];then
echo ├в variable-${var} is interget├в
else
echo ├в not iteger├в
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2005 08:23 PM
тАО11-13-2005 08:23 PM
Re: Perl conditions HELP
Thanks for your quick reply. May i ask what is wrong with the line:
if (pos($PerlVar)) {system("'$scrptpath'/parset2xml -t '$FILE'");system("'$ExePath'/rm '$FILE'");else {system("'$ExePath'/mv -f '$FILE' '$temp'");'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2005 08:24 PM
тАО11-13-2005 08:24 PM
Re: Perl conditions HELP
Post that information to give script to that.
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2005 08:31 PM
тАО11-13-2005 08:31 PM
Re: Perl conditions HELP
# cat filename
DIFFLOTID,12[12]
# cat test.pl
#!/usr/contrib/bin/perl
open FD, "filename" || die "Can not open file: $!";
while (
{
$Var=(split (/,/))[1] if /DIFFLOTID/;
print "$Var\n";
}
print $var . "\n";
if ( $Var =~ m/^[0-9][0-9]*[\.[0-9][0-9]*]{0,1}$/g )
{
print "ok done" . "\n";
}
else {
print "sorry\n";
}
# perl test.pl
12[12]
ok done
# Just change your content as,
#!/usr/contrib/bin/perl
open FD, "filename" || die "Can not open file: $!";
while (
{
$Var=(split (/,/))[1] if /DIFFLOTID/;
print "$Var\n";
}
print $var . "\n";
if ( $Var =~ m/^[0-9][0-9]*[\.[0-9][0-9]*]{0,1}$/g )
{
system("'$scrptpath'/parset2xml -t '$FILE'");system("'$ExePath'/rm '$FILE'");
}
else {system("'$ExePath'/mv -f '$FILE' '$temp'");'
}
##
That is it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2005 08:35 PM
тАО11-13-2005 08:35 PM
Re: Perl conditions HELP
#!/usr/contrib/bin/perl
$FILE="filename"
open FD, $FILE || die "Can not open file: $!";
while (
{
$Var=(split (/,/))[1] if /DIFFLOTID/;
print "$Var\n";
}
print $var . "\n";
if ( $Var =~ m/^[0-9][0-9]*[\.[0-9][0-9]*]{0,1}$/g )
{
system("'$scrptpath'/parset2xml -t '$FILE'");
system("'$ExePath'/rm '$FILE'");
}
else {system("'$ExePath'/mv -f '$FILE' '$temp'");'
}
exit 0
##
Took more attempts to get this ;(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2005 11:29 PM
тАО11-13-2005 11:29 PM
Re: Perl conditions HELP
From a perl perspective, the biggest thing that is wrong with your script is that is that is really is a shell script more than a perl program. You can do it al in perl, as written earlier.
Does the input to be tested for look like:
DIFFLOTID 123.455
followed by a ] or not?
I think the single regexpr for that, testing that word followed by the value is readably written as:
/DIFFLOTID\s+\d+\.\d+]?
that is:
- word
- one or more whitespace chars
- one or more decimal
- a period
- one or more decimal
- zero or one ]
If you prefer to do the action in the shell then you could do something like:
perl -ne '$x=1 if (/DIFFLOTID\s+\d+\.\d+]?/); print $x if eof' $FILE
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2005 11:54 PM
тАО11-13-2005 11:54 PM
Re: Perl conditions HELP
In a shell script one way to do this appears below. For example, to test whether or not ${X} is numeric (0..9):
# X=123
# if [ `expr ${X} : '[0-9]*'` -eq `expr ${X} : '.*'` ]; then
> echo "is_numeric"
> else
> echo "is_NOT_numeric"
> fi
This works by returning and comparing the number of characters in each 'expr'ession. If the number of *numeric* characters in the first expression is equal to the total number of characters in the second expresssion, then the first expression must consist only of (decimal) digits and therefore be "numeric".
Regards!
...JRF...