sed substitute / for \ : error "Function can not be parsed"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed substitute / for \ : error "Function can not be parsed"
# 1  
Old 07-17-2006
sed substitute / for \ : error "Function can not be parsed"

Hello all,

I have a weird issue when trying to substitute the slashes into backslashes.

If I execute this on the command-line (bash / ksh) I get the path correctly translated with backslashes instead of slashes.

Code:
>  echo $PWD | sed 's/\//\\/g'

However, when I put this in my script to have the output in the variable "newpwd" I get the error "sed: 0602-404 Function s/\//\\/g can not be parsed."

Code:
Code:
----------------------------------------------
#! /bin/sh
newpwd=`echo $PWD | sed -e 's/\//\\/g'`
echo $newpwd
----------------------------------------------

Does anyone know what's going on here?
How can I then translate the / into \ ?

Many thanks in advance!

Tom
# 2  
Old 07-17-2006
try this,

not tested
Code:
abc=`echo $PWD | sed 's/\//\\\\/g'`
echo $abc

# 3  
Old 07-17-2006
For more legibility, you can use the character of your choice as sed substitution delimiter instead of /
Try this :
Code:
#! /bin/sh
newpwd=`echo $PWD | sed -e 's_/_\\_g'`
echo $newpwd

Jean-Pierre.
# 4  
Old 07-18-2006
MySQL

Thanks guys!

matrixmadhan's solution worked nicely Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help to get the parsed output of "iostat" command

Hi, I have a requirement where parsed output from various linux commands like top, netstat, iostat, etc. will be the input for one javascript with the parsed output from these commands converted to JSON format For "iostat" command, since there are two outputs - one w.r.t CPU utilization and... (2 Replies)
Discussion started by: gopivallabha
2 Replies

2. Shell Programming and Scripting

In Vi "sed" substitute word on a specific line

i need to substitute word on a specific line. I was able to do it on command line like below but it is not working in vi. command line like below: sed -e '8s/table_name/schema.table_name/' file_name. in vi table_name and schema are my positional parameters that i pass into the script. ... (5 Replies)
Discussion started by: pimmit22043
5 Replies

3. Shell Programming and Scripting

Bash script fails with "function: not found" error

Hello everyone, I am having problems figuring this out. This script below is supposed to create a list of file names with their "md5sum", in a file "lib-list.txt" When I run it "sh component-list.sh " I get this:component-list.sh: 4: component-list.sh: function: not found component-list.sh:... (4 Replies)
Discussion started by: joemb
4 Replies

4. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

5. Shell Programming and Scripting

How do I grep with sed and substitute a "#" on that line

Hey all, I am trying to disable a certain cronjob before I run a backup. I want to be able to add/remove a "#" from the beginning on the crontab line it is located on. Here is the crontab: 46 11 * * * /etc/webmin/cron/tempdelete.pl @daily /etc/webmin/time/sync.pl */5 * * * *... (4 Replies)
Discussion started by: eg mike
4 Replies

6. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

7. Shell Programming and Scripting

How to substitute "\" by "\/" using SED?

Input: a/b/c Output required: a\/b\/c This does not work: sed s/'\/'/'\//'/g (6 Replies)
Discussion started by: indianjassi
6 Replies

8. HP-UX

ERROR: more than one instance of overloaded function "vprintf" has "C" linkage

Hi people! I've got this own library: -------------------------------------------- Personal.h -------------------------------------------- #ifdef __cplusplus extern "C" { #endif #include <stdio.h> #include <stdarg.h> #include <string.h> ... (0 Replies)
Discussion started by: donatoll
0 Replies

9. Shell Programming and Scripting

Can "sed" substitute word on a specific line?

Hello experts, I know line number of the word I want to replace. Can "sed" substitute word on a specific line? As well, can sed substitute words inside a specific patten. ex. <word>lalala</word> #replace anything between <word> and </word> minifish (2 Replies)
Discussion started by: minifish
2 Replies

10. Programming

How to convert the "select" function into a "poll" function

i have a program using the select function but i want to convert it to poll... how can i do this? thanks in advance... :) (1 Reply)
Discussion started by: rbolante
1 Replies
Login or Register to Ask a Question