1819575 Members
2922 Online
109603 Solutions
New Discussion юеВ

Re: parse

 
SOLVED
Go to solution
andi_1
Frequent Advisor

parse

Hi guys,

Suppose I have the following strings:
test.yara.Z
and
test.yara

How can determine whether there is a something else specified after .yara? So, in the first case, there is another extension specified after yara?

Thank you!
5 REPLIES 5
H.Merijn Brand (procura
Honored Contributor

Re: parse

From where? perl, sed, awk, sh, ksh, tcsh, csh, ...
Enjoy, Have FUN! H.Merijn
andi_1
Frequent Advisor

Re: parse

Simple bourne sh!
Bill McNAMARA_1
Honored Contributor
Solution

Re: parse

tests $F for 2 dots + numbers
ie: 1.2.3 and returns VALUE=1:

echo $F | grep -E -q "^[0-9]+\.[0-9]+\.[0-9]+$" && VALUE=1

tests for just number:
echo $F | grep -E -q "^[0-9]+$" && VALUE=2

I'm sure you can work on it to remove the [0-9] for files.

This tests for extension xml:

if [ "${_Input#*.}" != "xml" ]; then
echo "xml"
fi

Hope that's a quick start
Later,
Bill
It works for me (tm)
James R. Ferguson
Acclaimed Contributor

Re: parse

Hi:

Perhaps something like this:

#!/usr/bin/sh
X=`echo ${1##*.}`
if [ "$X" != "yara" ]
then
echo "...unexpected basename"
else
echo "...basename OK"
fi
#.end.

Regards!

...JRF...
H.Merijn Brand (procura
Honored Contributor

Re: parse

man basename
Enjoy, Have FUN! H.Merijn