Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using the IF statement

Status
Not open for further replies.

roger55

Programmer
Sep 1, 2003
3
US
I need to select a range of files in an If statement.

The current code does this:
for x in `cat $HOME2/tmp/SFA_rpt7.ctl`
do
if [ -s $x]
then

I want to only select files in a range like so:

if ( $x >= A600.prn and $x <= A699.prn )
or ( $x >= A720.prn and $x <= A720.prn)
then

I also need to do the reverse logic like this by
selecting files that are NOT in these ranges.
 
If all files have the same name format why don't you just do what you want:

Code:
   for x in `cat $HOME2/tmp/SFA_rpt7.ctl`
   do
     if [[ &quot;$x&quot; < &quot;A600.prn&quot; ]]
     then
        # do whatever 
     elif [[ &quot;$x&quot; >= A600.prn && &quot;$x&quot; <= &quot;A699.prn&quot; ]]
     then
        # do something else
     elif [[ &quot;$x&quot; >= &quot;A720.prn&quot; && &quot;$x&quot; <= &quot;A720.prn&quot; ]]
        # do more stuff
     else
        # whaterever to be done
     fi
   done

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
You can also consider the case statement, something like this:
Code:
case $x in
A6??.prn|A720.prn)
  What do do here
  ;;
AnotherPattern)
  Another stuff
  ;;
*)
  Otherwise stuff
  ;;
esac

Hope This Help
PH.
 
I tried this command but get a syntax error:

if [ ! \( -s $x -ge A600.prn -a -s $x -le A699.prn \) -a ! \( -s $x -ge A800.prn -a -s $x -le A899.prn \) ]
then
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top