![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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
Cheers Helen ![]() added code tags for readability --oombera Last edited by oombera; 02-19-2004 at 11:31 AM.. |
|
||||
|
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 |
|
||||
|
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 |
|
||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|