The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
foreach loop ROOZ Shell Programming and Scripting 3 06-05-2008 03:20 PM
foreach loop abch624 Shell Programming and Scripting 1 03-19-2008 09:34 PM
foreach folder eltinator Shell Programming and Scripting 7 08-13-2007 02:37 AM
foreach/grep help! JimWork Shell Programming and Scripting 6 07-27-2007 04:25 PM
How to define two variable in foreach command?? geoquest Shell Programming and Scripting 14 08-22-2002 06:11 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-20-2002
geoquest geoquest is offline
Registered User
  
 

Join Date: Apr 2002
Location: oman
Posts: 25
foreach command ?!

SaLAam

What is the best way to change a word withing a files name. I know I'm not clear enough I will give example : -


I have in /test/test N number of files like this

1662_WAITING
1666_WAITING
1670_DONE
1678_DONE
1663_WAITING
1667_WAITING
1673_WAITING
1679_WAITING
1664_WAITING
1668_WAITING
1676_TAPE_ERROR
1683_DONE
1665_WAITING
1669_DONE
1677_TAPE_ERROR
1685_DONE

I want to change the word "####_WAITING" to "####_DONE" or for all the words after the _ at once if possiple. I tried foreach command and I mange to get something like "####_WAITING_DONE" but this is not what I want :-(.

thanks in advance

Abdulkarim
  #2 (permalink)  
Old 05-20-2002
Bab00shka Bab00shka is offline
Registered User
  
 

Join Date: Apr 2002
Location: Chesterfield, UK
Posts: 123
Hi Abdulkarim

Try this:
Code:
for i in `ls /test/test`
do
   echo $i | grep "WAITING" >/dev/null
   if [ $? -eq 0 ]
   then
      j=`echo $i | sed "s/WAITING/DONE/"`
      mv /test/test/$i /test/test/$j
   fi
done
Let me know how you get on.

Cheers
Helen

added code tags for readability --oombera

Last edited by oombera; 02-19-2004 at 11:31 AM..
  #3 (permalink)  
Old 05-20-2002
geoquest geoquest is offline
Registered User
  
 

Join Date: Apr 2002
Location: oman
Posts: 25
do command not found!!

hi helen,

Thanks for your help, but when I tried your command it's not working saying do command not found!!

Maybe I forget to tell you I'm using unix sun 5.6.
and I don't not know what is "fi" for in ur script.I want to know if possiple why u direct the output to /dev/null ??? I'm still a very new unix user :-D.


thanks
Abdulkarim
  #4 (permalink)  
Old 05-20-2002
hugo_perez hugo_perez is offline
Registered User
  
 

Join Date: Apr 2002
Location: Argentine - that better than to eat meat and to drink wine (both Argentineans)?.
Posts: 132
Try with sed

man sed.

Regards. Hugo.
  #5 (permalink)  
Old 05-20-2002
Bab00shka Bab00shka is offline
Registered User
  
 

Join Date: Apr 2002
Location: Chesterfield, UK
Posts: 123
Hi Abdulkarim

I see, I'm using HP-UX 11.00 with a Korn Shell. I'm not sure how Sun 5.6 differs. What shell are you using?

I must admit I have not heard of the 'foreach' statement. Are you doing a shell script or using a programming language?

'fi' is the end of the 'if' statement. If statement syntax is as follows:

if <test>
then
<list of commants>
fi

I have redirected output to /dev/null because I don't want the result of the echo statement to appear on the screen. I just want to know the return value of the statement. If you don't already know, anything that goes to /dev/null 'disappears'. Its a bit like a waste bin.

Cheers
Helen
  #6 (permalink)  
Old 05-20-2002
thehoghunter
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
The foreach is in csh.

He is probably running the script the same way (which is why 'do' isn't found). Solaris differs greatly to HP but the shells should work pretty much the same.

Your script, Helen, does work on under Solaris 5.6 in ksh.
Closed Thread

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0