SunQuest
           UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old December 30th, 2004, 12:20 AM
izza_azhar izza_azhar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 49 izza_azhar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 33 m 57 sec
Reputation Power: 4
plese help-comparison string

i want to search for file that start with file200411*. i can't pass the variable. should i use grep?
the output will appear as "nor exist" although there is a file in a directory
so..please help

#!/bin/sh

yr=2004
mth=11

for file in ls file*
do
if [ "$file" = "file$yr$mth*.txt" ]
then
echo "file exist, $file"
else
echo "file not exist"
fi
done

Reply With Quote
  #2  
Old December 30th, 2004, 06:14 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 44 m 45 sec
Reputation Power: 9
use 'if' for numerical tests
use 'case' for all other
Code:
for file in `ls`
do
    case $file in file$yr$mth*.txt) XXX= ;; *)  XXX=not ;; esac
    echo "file $file does $XXX exist"
done

Last edited by guggach : December 30th, 2004 at 06:17 AM. Reason: typo

Reply With Quote
  #3  
Old December 30th, 2004, 06:36 AM
christo's Avatar
christo christo is offline
Introspective
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Nov 2001
Location: London, UK
Posts: 3,296 christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 1 h 5 m 42 sec
Reputation Power: 101
Send a message via ICQ to christo Send a message via Yahoo to christo
Quote:
Originally Posted by izza_azhar
i want to search for file that start with file200411*. i can't pass the variable. should i use grep?
the output will appear as "nor exist" although there is a file in a directory
so..please help

#!/bin/sh

yr=2004
mth=11

for file in ls file*
do
if [ "$file" = "file$yr$mth*.txt" ]
then
echo "file exist, $file"
else
echo "file not exist"
fi
done



why not just use find?
Code:
find . -name "file200411*" -print


christo

or does this definititel h

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > plese help-comparison string


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway