|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
You're not actually applying the sed command to anything.
You'd need echo $i |sed .... |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > need help with a basic loop |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|