Solved

Linux Shell Scripting:  Replace Slash

Posted on 2013-11-12
3
322 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 200 total points
ID: 39642013
$ bar=${f////%2f}


$ echo ${bar}
0
 
LVL 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 200 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 100 total points
ID: 39642470
The first - elegant! - solution needs just a tiny correction:

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

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Samba Question 11 103
Intel fortran compiler (ifort) 5 56
How to change the nameserver on Ubuntu Server 6 71
IP 10.0.1.2 / 255.0.0.0 61 73
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

740 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