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

Closed Thread
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 July 16th, 2004, 12:58 PM
bman79 bman79 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 4 bman79 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unix Scripting Question

I have multiple files in one directory starting with POS. ex. POS123.date
POS345.date
I want to touch each POS* file in the directory to create a 0 byte file called:
POS123.date.complete
POS345.date.complete

What is the command to use to do this? This will be in a script and there will be multiple files in this directory beginning with POS.

Bman79

Reply With Quote
  #2  
Old July 16th, 2004, 01:30 PM
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
for file i `ls pos*`
do something whith $file
done

Reply With Quote
  #3  
Old July 16th, 2004, 02:18 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,307 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 4 h 28 m 57 sec
Reputation Power: 48
Code:
for filename in /path/to/directory/POS*
do
     echo $filename | grep -q "complete"
     if [ $? -eq 0 ] ; then
        touch "$filename".date.complete
     fi
done

I'm assuming you will run this day after day, so you do not want to 'retouch' files with the name *.complete"

Reply With Quote
  #4  
Old July 17th, 2004, 06:52 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
thank you jim for:
for filename in /path/to/directory/POS*
i used (will no longer)
for filename in `ls -options /path/to/directory/POS*`
you show me, the shell can resolve it, thanks again.
i don't really agree with your (xpg4)grep
i propose:
case $filename in *complete) continue;; esac
OR
case $filename in *complete*) continue;; esac
the second, is the same as your grep; so my version:


for filename in /path/to/directory/POS*
do
case $filename in *complete) continue;; esac
touch $filename.date.complete
done

Reply With Quote
  #5  
Old July 21st, 2004, 06:53 AM
bman79 bman79 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 4 bman79 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank You. This worked!

This was very helpful.

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Unix Scripting Question


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 4 hosted by Hostway