want to escape forward slash, i tired but not working.. statement garbled
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
want to escape forward slash, i tired but not working.. statement garbled
Hi Team,
could you please help on below? I am trying to use sed command to repalce one string with other but somehow replacement string contains forwards slash hence getting the error statement garbled!
please help
from_row contains /wu9m<h-8$
Fix is require at
sql_text=`cat $staging_population_program | head -$before_lines | sed "s/\&\&1/$from_row/" | sed "s/\&\&2/$to_row/" | sed "s/\&\&3/$region/"`
nygespappd29:/data/apps/pnbos/scripts > ./populate_staging_posn.ksh -C /data/apps/pnbos/config/HK_EOD.cfg -f C
ALCSTG
START ./populate_staging_posn.ksh at Monday, May 2, 2011 03:07:30 PM BST
--> Running Staging POSN for ASIA at Monday, May 2, 2011 03:07:30 PM BST
--> Loading profit centres at Monday, May 2, 2011 03:07:30 PM BST
--> Splitting for multiple engines at Monday, May 2, 2011 03:07:48 PM BST
--> Running multiple engines at Monday, May 2, 2011 03:07:51 PM BST sed: command garbled: s/\&\&2//wu9m<h-8$/
sed: command garbled: s/\&\&2//wu9m<h-8$/
sed: command garbled: s/\&\&1//wuCm<h-8$/
sed: command garbled: s/\&\&1//wuCm<h-8$/
It is still not working, I tried what you have suggested:
Code:
...
echo $from_row
sed "s|to_row|$from_row" # there is no closing pipe character on the command here
echo $to_row
...
I tired this as well, it hung:
Code:
#!/bin/ksh
...
sed "s|to_row|$from_row|" # it's hanging because sed is waiting for something to process
# The original code you gave, piped the output from a cat command
# through sed. Also, this will replace the text-literal "to_row",
# not the contents of the variable $to_row
...
By default, if you enter a sed command, and don't pipe/redirect anything to it, it will wait for you to type something on the command line.
Code:
rob@rob-debian:~$ sed "s|$to_row|$from_row|"
Cheese
Cheese
Pickles
Pickles
Hello, how are you?
Hello, how are you?
Hi, how are you?
/wu9m<h-8$, how are you?
The sort of thing you need is:
Code:
#!/bin/bash
to_process="Hi, how are you?"
from_row='/wu9m<h-8$'
to_row='Hi'
processed=$(echo $to_process | sed "s|$to_row|$from_row|")
echo $processed
exit 0
rob@rob-debian:~$ ./hello.sh
/wu9m<h-8$, how are you?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.