Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Linux Shell Scripting:  Replace Slash

Posted on 2013-11-12
3
Medium Priority
?
343 Views
Last Modified: 2013-11-12
How can I replace all slashses with %2f
?
 f="abc/xyz/123"
 echo ${f}

Open in new window

The result should be:
abc%2fxyz%2f123
0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Assisted Solution

by:unknown_routine
unknown_routine earned 800 total points
ID: 39642013
$ bar=${f////%2f}


$ echo ${bar}
0
 
LVL 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 800 total points
ID: 39642159
You mean to replace them in the string f ?

This will replace them:

f=`echo $f | sed 's/\//\%2f/g'`

echo ${f}

But I'm not getting why you would want this ;)
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 400 total points
ID: 39642470
The first - elegant! - solution needs just a tiny correction:

f=${f//\//%2f}
echo $f
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question