Solved

Linux Shell Scripting:  Replace Slash

Posted on 2013-11-12
3
311 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
3 Comments
 
LVL 15

Assisted Solution

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


$ echo ${bar}
0
 
LVL 37

Assisted Solution

by:Gerwin Jansen
Gerwin Jansen 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

930 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now