Results 1 to 6 of 6
Hello,
I have a situation where I need to remove the text "radio28" including the quotes from many shell scripts with the .sh extension. I have been learning SED and ...
- 06-04-2009 #1
Sed Assistance
Hello,
I have a situation where I need to remove the text "radio28" including the quotes from many shell scripts with the .sh extension. I have been learning SED and AWK from this site and other references. My goal is to automate this in a bash shell script on RHEL4.
The files are located in /usr/local/bin
Currently my attempt at this worked. However I used redirection to a tmp folder and I lost all my file attributes. I know there is a way to use the -i flag. However I have not been successful.
Here is what I have so far:
Is there a way to run this from inside of /usr/local/bin without wrecking the attributes. Also without the redirection.Code:#! /bin/bash for x in `ls /usr/local/bin/` ; do sed 's/"radio28"/ /g' /usr/local/bin/$x > /usr/local/bin/tmp/$x done
Your help is appreciated.
Jaysunn
- 06-04-2009 #2Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
What do you mean not successful with the -i option? What happened?
The command should look like:
Code:sed -i 's/"radio28"/ /g' /usr/local/bin/$x
- 06-04-2009 #3
When adding that line to my script:
When executed I receive this Message. "This may be related to me testing on MAC OSX Terminal". I get the below error for every file sed tries to input.Code:#! /bin/bash for x in `ls /usr/local/bin/` ; do sed -i 's/"radio28"/ /g' /usr/local/bin/$x done
Code:sed: 1: "/usr/local/bin/check_gr ...": extra characters at the end of l command
Thanks for the reply.
Jaysunn
- 06-04-2009 #4Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
If you're testing on OSX and not Linux then that's the problem. The -i option in OSX sed requires a value. You have to test this on Linux.
Here's a link to OSX sed manpage.
Mac OS X Manual Page For sed(1)
- 06-05-2009 #5Linux User
- Join Date
- Aug 2006
- Posts
- 458
- 06-05-2009 #6Just Joined!
- Join Date
- Apr 2009
- Posts
- 33
basically, you need to remove "radio28" from shell scripts that have an .sh extension
and are located in /usr/local/bin and are executable
Right?
in that case I would do this
cd /usr/local/bin
for f in *.sh
do
if [ $(grep -c '"radio28"') -gt 0 ]; then
sed 's/"radio28"//g' $f > __f && mv __f $f && chmod 755 $f
fi
done
note:
the grep is for doing the job only for the files that actually have that string
chmod 755 should make the script executable
and this is done in place (no need to use /tmp)
of course you must have the right permissions to write in /usr/local/bin


Reply With Quote
