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:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old October 27th, 2004, 03:35 PM
sharc sharc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 4 sharc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question need help with a basic loop

Hi.
I'm new to unix and am stumped on this problem. . .. I've a file that contains a text list consisting of names some of which are like "currentfile-sm", and for each of these with an "-sm" I'd like to delete. My loop is as follows:

for i in `cat allItems.lis`
do
sed 's/[a-zA-Z1-9][a-zA-Z1-9]*[-sm]/ /g'
done

but it hangs! Can anyone tell me where I'm going wrong? I'm attempting this in both the ksh and sh shell, niether of which will work.

Reply With Quote
  #2  
Old October 28th, 2004, 09:41 AM
andyb1ack andyb1ack is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 60 andyb1ack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 14 sec
Reputation Power: 4
You're not actually applying the sed command to anything.

You'd need
echo $i |sed ....

Reply With Quote
  #3  
Old November 1st, 2004, 08:30 AM
andyb1ack andyb1ack is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 60 andyb1ack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 14 sec
Reputation Power: 4
Not sure what your sed command is trying to achieve but that was why it was hanging.

If I understand you correctly then you have a file listing files you want to remove (those ending with -sm) and other files you want to keep. If this is the case then I'd do the following:

List all the files you want to delete:
grep "-sm$" allItems.lis

Confirm you're happy you're only listing the ones you want to delete, then add the remove command (this assumes there's only one field on each line):
grep "-sm$" allItems.lis |awk '{print "rm "$1}'

Confirm these commands look ok, then run:
grep "-sm$" allItems.lis |awk '{print "rm "$1}' |ksh -x

Reply With Quote
  #4  
Old November 2nd, 2004, 03:37 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
andy is correct, and your sed
sed 's/[a-zA-Z1-9][a-zA-Z1-9]*[-sm]/ /g'
match:
abba1-
abba1s
abba1m
changing all three to a space
never matching 'abba1-sm'

the unix cmd: rm [A-z1-9]*[A-z1-9]-sm
will do the job

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > need help with a basic loop


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