Help with Permission Denied on script with sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with Permission Denied on script with sed
# 1  
Old 05-11-2012
Help with Permission Denied on script with sed

I am trying to develop a script to replace a lowercase URLs with an upper case URLs in HTM files.

Basically.. replace href="somelowercaseurl" with href="SOMEUPPERCASEURL". In place.

the href's are not located in any specific position in the file.

Here is my shell script :

Code:
export PATH=$PATH
if [ $# -eq 0 ];
then
 echo "Syntax: hreftoupper [Dir needed.. In upper case]"
 exit 1
fi
for f in ./$1/*.HTM
do
echo "processing $f"
sed -ir `s/href=\"[^\"]*\"/\U\1/g` `$f`
done
echo "done"

..

I am getting permission denied on the HTML file. From the prompt I can VI the file though so I know I have permission. I assume something is wrong with the script above.. any help would be appreciated.
# 2  
Old 05-11-2012
You are putting $f in ` ` backticks.

This attempts to execute the HTML file, as if it were a script. Since it's not set executable, it gives you permission denied. Use double quotes " " instead of backticks.

You are also putting your regex in backticks. This attempts to execute it, and will complain 'no such file or directory'. Put it in single quotes ' '.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 05-11-2012
Quote:
sed -ir `s/href=\"[^\"]*\"/\U\1/g` `$f`
Wherever you have a backtick ` it should be a different type of quote character. Single quotes round the sed string and double quotes round the filename.
Code:
sed -ir 's/href=\"[^\"]*\"/\U\1/g' "$f"

Ps. I can't vouch for the actual sed command, only the basic syntax.
This User Gave Thanks to methyl For This Post:
# 4  
Old 05-11-2012
Thanks Methyl... problem now is it seems to think the first char of the filename in $f is a command:
Error :
Code:
./testtoupper.sh: line 11: s/href="[^"]*"/U1/g: No such file or directory
sed: -e expression #1, char 1: unknown command: `A'

---------- Post updated at 01:59 PM ---------- Previous update was at 01:55 PM ----------

Sorry Corona688.. I missed your reply before Methol, thanks for your help... I am getting a new error
Code:
sed: -e expression #1, char 24: invalid reference \1 on `s' command's RHS

The code now

Code:
for f in $1/*.HTM
do
echo "processing $f"
sed -ir 's/href=\"[^\"]*\"/\U\1/g' "$f"
done

# 5  
Old 05-11-2012
You have no \( \) on the left hand side, so nothing inside to reference with \1 there.
This User Gave Thanks to Corona688 For This Post:
# 6  
Old 05-11-2012
ref to \1

Quote:
Originally Posted by Corona688
You have no \( \) on the left hand side, so nothing inside to reference with \1 there.
Thanks Corona688.. Are you saying I need to do something like this?:

Code:
sed -ir 's/\(href=\"[^\"]*\"\)/\U\1/g' "$f"

I tried it this way above and got the following error message

sed: -e expression #1, char 23: unknown option to `s'

EDIT... no typo on my end.. IT WORKED!... thanks

Last edited by smarty; 05-11-2012 at 05:14 PM.. Reason: tried it
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

Permission denied

Trying to get date into the txt file. It says Permission denied. echo $(date +%I:%M:%S_%D) >> /tmp/systemd_suspend_test_err.txt exec 2>> /tmp/systemd_suspend_test_err.txt if ; then # Do the thing you want before suspend here echo "we are suspending $(date +%I:%M:%S_%D)." elif ;... (5 Replies)
Discussion started by: drew77
5 Replies

2. Shell Programming and Scripting

Permission denied running shell script in opensuse

Hello, I am having an odd problem in open suse 12. I have a shell script and when I try to run it, I get "permission denied" The permissions from ls -l are, -rw------- 1 user1 users 25904 Jan 10 16:26 script.sh I have tried to change the permissions in dolphin but this does not change the... (5 Replies)
Discussion started by: LMHmedchem
5 Replies

3. Linux

Permission denied

I am using korn shell When I type in Telnet on cmd line, I get message "cannot execute" How can I get permission to execute command ? In which dir is telnet located ? I looked in /usr/bin dir. but its not there Thanks (1 Reply)
Discussion started by: paramshamnani
1 Replies

4. Shell Programming and Scripting

Trying to create a script to run as root, permission denied

Hello all, I am trying to create a script or a .command file that will run for me and my other techs on many, many Mac OSX computers that will add a file to the /etc/ folder called /etc/launchd.conf Every time I try to run the script, I get "Permission Denied" when trying to put the file into... (13 Replies)
Discussion started by: DonnieNarco
13 Replies

5. Shell Programming and Scripting

Permission denied

I created a user so that when he logs in he will be directed to a menu /etc/passwd user1:x:115:1:Support -SysAd:/export/home/user1:/export/home/suppotrmenu/script.sh However when I logged in remotely from another server by ssh user1@1.1.1.1 , it saysexport/home/suppotrmenu/script.sh:... (4 Replies)
Discussion started by: lhareigh890
4 Replies

6. Shell Programming and Scripting

shell script and Permission denied

Have the following in a .sh file. printf "Installing ... \ r" cd $ ORG_DIR / a_a . / configure> error.log Make 1> error.log 2> error.log make install> error.log But when I run I get the following. install.sh: line 270:. / configure: Permission denied make: *** No rule two make target... (3 Replies)
Discussion started by: Mumie
3 Replies

7. Shell Programming and Scripting

Executing expect script giving message as bad interpreter: Permission denied

Hi Gurus, I am new to scripting and needs your help in expect script used for telnet. I wrote a simple script as #!/usr/bin/expect-5.43 -f spawn telnet localhost 2233 expect "password:" send "secret\r" send "i data.cnbc.com\r" send "exit\r" expect eof When I am trying to execute... (2 Replies)
Discussion started by: niks_yv
2 Replies

8. UNIX for Advanced & Expert Users

Permission denied

Hi, I can not execute a .env file $ . /Data/oracle/d03/mydbora/8.0.6/MYDB.env -bash: /Data/oracle/d03/mydbora/8.0.6/MYDB.env: Permission denied Even if : -rwxrwxrwx 1 oracle dba 2903 Mar 5 2007 /Data/oracle/d03/mydbora/8.0.6/MYDB.env Please help. Many thanks. (1 Reply)
Discussion started by: big123456
1 Replies

9. UNIX for Dummies Questions & Answers

Permission Denied

I just started computer science at UW Milwaukee. When I access the university Solaris system from PuTTY, I get permission denied when I try to access the file I wrote. Now I really have no idea what I'm doing, I just don't understand why I get permission denied in my won directory. Thank You ... (0 Replies)
Discussion started by: howeezy
0 Replies

10. UNIX for Dummies Questions & Answers

permission denied??

i'm trying to set up my internet connection and i was told i need to edit the file /etc/ppp/pap-secrets but i get a permission denied message...why?? (6 Replies)
Discussion started by: justchillin
6 Replies
Login or Register to Ask a Question