Re: [WISPA] Linux command question
On Sat, Dec 15, 2007 at 09:45:50AM -0600, Mike Hammett wrote: Would the following command remove ../../Templates/ from all files in the /home/devicsil/public_html/Templates directory? for file in ls /home/devicsil/public_html/Templates ; do sed -e 's/..\/..\/Templates\///g' $file echo done That will remove all instances of somecharactersomecharacter/somecharactersomecharacter/Templates/ from those files. Your sed command as written will only output the changes to stdout, which is great for debugging before you actually change the files. You also need to use backticks around the ls command so that it will be run in a subshell and it's output used in the for loop rather than looping on ls and /home/devicsil/public_html/Templates. If your sed supports the inplace argument, as in FreeBSD's sed, you can specify something like: sed -i.bak -e 's|\.\./\.\./Templates/||g' $file I think that will do what you intend to do by only changing instances of ../../Templates/ instead of, possibly, somedirectoryname/aa/Templates/, if such names are a possibility in the source files. Your original regex would have matched the later string and removed me/aa/Templates/. If your sed does not support the inplace argument, you will need to do something like: for file in `ls /home/devicsil/public_html/Templates` ; do mv $file $file.bak; sed -e 's|\.\./\.\./Templates/||g' $file.bak $file; echo : done; I haven't run that so it may have bugs. Test first and, as always, have a backup. HTH, -- Scott LambertKC5MLE Unix SysAdmin [EMAIL PROTECTED] WISPA Wants You! Join today! http://signup.wispa.org/ WISPA Wireless List: wireless@wispa.org Subscribe/Unsubscribe: http://lists.wispa.org/mailman/listinfo/wireless Archives: http://lists.wispa.org/pipermail/wireless/
Re: [WISPA] Linux command question
On Sun, Dec 16, 2007 at 03:02:30AM -0600, Scott Lambert wrote: If your sed does not support the inplace argument, you will need to do something like: for file in `ls /home/devicsil/public_html/Templates` ; do mv $file $file.bak; sed -e 's|\.\./\.\./Templates/||g' $file.bak $file; echo : done; I haven't run that so it may have bugs. Test first and, as always, have a backup. I should mention, if only for the newbies who might be watching, that the above makes several assumptions about what is in /home/devicsil/public_html/Templates, including: 1) There are no files with spaces in their name. 2) There are no subdirectories. If there are we just renamed them to have a .bak extension and broke lots of stuff. 3) You don't want to change any files whose names begin with ., i.e. .htaccess and friends. If any of those assumptions are not true, you probably need to dump the for loop and use something along the lines of: find /home/devicsil/public_html/Templates/ -type f mumblemumble -print0 | \ xargs -0 mumblemumble sed mumblemumble where you might want to replace sed with a script that does the mv, sed, echo stuff, if necessary. Anyway, good luck! -- Scott LambertKC5MLE Unix SysAdmin [EMAIL PROTECTED] WISPA Wants You! Join today! http://signup.wispa.org/ WISPA Wireless List: wireless@wispa.org Subscribe/Unsubscribe: http://lists.wispa.org/mailman/listinfo/wireless Archives: http://lists.wispa.org/pipermail/wireless/
[WISPA] Linux command question
Would the following command remove ../../Templates/ from all files in the /home/devicsil/public_html/Templates directory? for file in ls /home/devicsil/public_html/Templates ; do sed -e 's/..\/..\/Templates\///g' $file echo done - Mike Hammett Intelligent Computing Solutions http://www.ics-il.com WISPA Wants You! Join today! http://signup.wispa.org/ WISPA Wireless List: wireless@wispa.org Subscribe/Unsubscribe: http://lists.wispa.org/mailman/listinfo/wireless Archives: http://lists.wispa.org/pipermail/wireless/
Re: [WISPA] Linux command question
How about: rm -R -f /home/devicsil/public_html/Templates/* Remove, recurse, force all files from directory. Mike Hammett wrote: Would the following command remove ../../Templates/ from all files in the /home/devicsil/public_html/Templates directory? for file in ls /home/devicsil/public_html/Templates ; do sed -e 's/..\/..\/Templates\///g' $file echo done - Mike Hammett Intelligent Computing Solutions http://www.ics-il.com WISPA Wants You! Join today! http://signup.wispa.org/ WISPA Wireless List: wireless@wispa.org Subscribe/Unsubscribe: http://lists.wispa.org/mailman/listinfo/wireless Archives: http://lists.wispa.org/pipermail/wireless/ -- Scott Reed Owner NewWays Wireless Networking Network Design, Installation and Administration www.nwwnet.net (765) 855-1060 WISPA Wants You! Join today! http://signup.wispa.org/ WISPA Wireless List: wireless@wispa.org Subscribe/Unsubscribe: http://lists.wispa.org/mailman/listinfo/wireless Archives: http://lists.wispa.org/pipermail/wireless/
Re: [WISPA] Linux command question
sed doesn't remove files, though your command might produce a listing of the files stripped of all mention of $file in /home/devicsil. On Dec 15, 2007 9:45 AM, Mike Hammett [EMAIL PROTECTED] wrote: Would the following command remove ../../Templates/ from all files in the /home/devicsil/public_html/Templates directory? for file in ls /home/devicsil/public_html/Templates ; do sed -e 's/..\/..\/Templates\///g' $file echo done - Mike Hammett Intelligent Computing Solutions http://www.ics-il.com WISPA Wants You! Join today! http://signup.wispa.org/ WISPA Wireless List: wireless@wispa.org Subscribe/Unsubscribe: http://lists.wispa.org/mailman/listinfo/wireless Archives: http://lists.wispa.org/pipermail/wireless/ -- Dylan Oliver Primaverity, LLC WISPA Wants You! Join today! http://signup.wispa.org/ WISPA Wireless List: wireless@wispa.org Subscribe/Unsubscribe: http://lists.wispa.org/mailman/listinfo/wireless Archives: http://lists.wispa.org/pipermail/wireless/
Re: [WISPA] Linux command question
Its been awhile since I used sed, and I can not figure out to read and write to the same file. Since you are doing this with a backup of the files, correct? Here is a way to make it work mkdir newfiles for file in `ls .`; do sed -e 's|../../Templates/||g' $file newfiles/$file echo done The edited files will be in newfiles/ Note: I used | instead of / for the delimiter, sed can use different delimiters as long as you are consistent in the script. http://www.grymoire.com/Unix/Sed.html Ryan On Dec 15, 2007, at 10:02 AM, Mike Hammett wrote: I'm not looking to remove the files, but to remove the text string ../../Templates/ from those files. - Mike Hammett Intelligent Computing Solutions http://www.ics-il.com - Original Message - From: Mike Hammett [EMAIL PROTECTED] To: WISPA General List wireless@wispa.org Sent: Saturday, December 15, 2007 9:45 AM Subject: [WISPA] Linux command question Would the following command remove ../../Templates/ from all files in the /home/devicsil/public_html/Templates directory? for file in ls /home/devicsil/public_html/Templates ; do sed -e 's/..\/..\/Templates\///g' $file echo done - Mike Hammett Intelligent Computing Solutions http://www.ics-il.com WISPA Wants You! Join today! http://signup.wispa.org/ WISPA Wireless List: wireless@wispa.org Subscribe/Unsubscribe: http://lists.wispa.org/mailman/listinfo/wireless Archives: http://lists.wispa.org/pipermail/wireless/ WISPA Wants You! Join today! http://signup.wispa.org/ WISPA Wireless List: wireless@wispa.org Subscribe/Unsubscribe: http://lists.wispa.org/mailman/listinfo/wireless Archives: http://lists.wispa.org/pipermail/wireless/ WISPA Wants You! Join today! http://signup.wispa.org/ WISPA Wireless List: wireless@wispa.org Subscribe/Unsubscribe: http://lists.wispa.org/mailman/listinfo/wireless Archives: http://lists.wispa.org/pipermail/wireless/
Re: [WISPA] Linux command question
It is not sed, but this ought to work... perl -pi -e 's/Templates//sgi'/path_to_directory_containing files/* You could also (recommended) have it create a backup file for every file edited (Google perl command line editing) or you could also find all the files containing the word templates and process only those.. e.g. perl -pi -e 's/Templates//sgi' `grep -l Templates /path_to_directory_containing files/*` Disclaimer - the above examples are just off the top of my head and have not been double-checked for accuracy, fitness for purpose, effectiveness, or anything else. Use at your own risk. John Ryan Langseth wrote: Its been awhile since I used sed, and I can not figure out to read and write to the same file. Since you are doing this with a backup of the files, correct? Here is a way to make it work mkdir newfiles for file in `ls .`; do sed -e 's|../../Templates/||g' $file newfiles/$file echo done The edited files will be in newfiles/ Note: I used | instead of / for the delimiter, sed can use different delimiters as long as you are consistent in the script. http://www.grymoire.com/Unix/Sed.html Ryan On Dec 15, 2007, at 10:02 AM, Mike Hammett wrote: I'm not looking to remove the files, but to remove the text string ../../Templates/ from those files. - Mike Hammett Intelligent Computing Solutions http://www.ics-il.com - Original Message - From: Mike Hammett [EMAIL PROTECTED] To: WISPA General List wireless@wispa.org Sent: Saturday, December 15, 2007 9:45 AM Subject: [WISPA] Linux command question Would the following command remove ../../Templates/ from all files in the /home/devicsil/public_html/Templates directory? for file in ls /home/devicsil/public_html/Templates ; do sed -e 's/..\/..\/Templates\///g' $file echo done - Mike Hammett Intelligent Computing Solutions http://www.ics-il.com WISPA Wants You! Join today! http://signup.wispa.org/ WISPA Wireless List: wireless@wispa.org Subscribe/Unsubscribe: http://lists.wispa.org/mailman/listinfo/wireless Archives: http://lists.wispa.org/pipermail/wireless/ WISPA Wants You! Join today! http://signup.wispa.org/ WISPA Wireless List: wireless@wispa.org Subscribe/Unsubscribe: http://lists.wispa.org/mailman/listinfo/wireless Archives: http://lists.wispa.org/pipermail/wireless/ WISPA Wants You! Join today! http://signup.wispa.org/ WISPA Wireless List: wireless@wispa.org Subscribe/Unsubscribe: http://lists.wispa.org/mailman/listinfo/wireless Archives: http://lists.wispa.org/pipermail/wireless/ -- John Vogel - [EMAIL PROTECTED] http://www.vogent.net 620-754-3907 Vogel Enterprises, LLC Information Services Provider serving S.E. Kansas WISPA Wants You! Join today! http://signup.wispa.org/ WISPA Wireless List: wireless@wispa.org Subscribe/Unsubscribe: http://lists.wispa.org/mailman/listinfo/wireless Archives: http://lists.wispa.org/pipermail/wireless/