Removing first forward slash from string

Clash Royale CLAN TAG#URR8PPP
up vote
-1
down vote
favorite
I'm trying to remove the first / from a string in a shell script.
For example
file:///path/to/file
and output to
file://path/to/file
bash regular-expression
New contributor
hugovdd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
-1
down vote
favorite
I'm trying to remove the first / from a string in a shell script.
For example
file:///path/to/file
and output to
file://path/to/file
bash regular-expression
New contributor
hugovdd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I'm trying to remove the first / from a string in a shell script.
For example
file:///path/to/file
and output to
file://path/to/file
bash regular-expression
New contributor
hugovdd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I'm trying to remove the first / from a string in a shell script.
For example
file:///path/to/file
and output to
file://path/to/file
bash regular-expression
bash regular-expression
New contributor
hugovdd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
hugovdd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 3 hours ago
Rui F Ribeiro
38k1475123
38k1475123
New contributor
hugovdd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 3 hours ago
hugovdd
11
11
New contributor
hugovdd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
hugovdd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
hugovdd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
2
down vote
accepted
If the string is in a shell variable, then you can use shell parameter expansion:
$ var='file:///path/to/file'
$ echo "$var///"
file://path/to/file
IMHO this is the true answer, as it doesn't rely on calls to other programs to answer the OP's question. Nicely done.
– bgregs
3 hours ago
add a comment |
up vote
0
down vote
Something like will do the work:
A="file:///path/to/file"
B=$(echo $A|sed 's@/@@')
without g at the end in sed the program will change only first occurrence
add a comment |
up vote
0
down vote
Here is a cheat sheet for various way of doing that with some fundamentals.
https://devhints.io/bash
1
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Anthony Geoghegan
2 hours ago
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
If the string is in a shell variable, then you can use shell parameter expansion:
$ var='file:///path/to/file'
$ echo "$var///"
file://path/to/file
IMHO this is the true answer, as it doesn't rely on calls to other programs to answer the OP's question. Nicely done.
– bgregs
3 hours ago
add a comment |
up vote
2
down vote
accepted
If the string is in a shell variable, then you can use shell parameter expansion:
$ var='file:///path/to/file'
$ echo "$var///"
file://path/to/file
IMHO this is the true answer, as it doesn't rely on calls to other programs to answer the OP's question. Nicely done.
– bgregs
3 hours ago
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
If the string is in a shell variable, then you can use shell parameter expansion:
$ var='file:///path/to/file'
$ echo "$var///"
file://path/to/file
If the string is in a shell variable, then you can use shell parameter expansion:
$ var='file:///path/to/file'
$ echo "$var///"
file://path/to/file
answered 3 hours ago
steeldriver
33.4k34982
33.4k34982
IMHO this is the true answer, as it doesn't rely on calls to other programs to answer the OP's question. Nicely done.
– bgregs
3 hours ago
add a comment |
IMHO this is the true answer, as it doesn't rely on calls to other programs to answer the OP's question. Nicely done.
– bgregs
3 hours ago
IMHO this is the true answer, as it doesn't rely on calls to other programs to answer the OP's question. Nicely done.
– bgregs
3 hours ago
IMHO this is the true answer, as it doesn't rely on calls to other programs to answer the OP's question. Nicely done.
– bgregs
3 hours ago
add a comment |
up vote
0
down vote
Something like will do the work:
A="file:///path/to/file"
B=$(echo $A|sed 's@/@@')
without g at the end in sed the program will change only first occurrence
add a comment |
up vote
0
down vote
Something like will do the work:
A="file:///path/to/file"
B=$(echo $A|sed 's@/@@')
without g at the end in sed the program will change only first occurrence
add a comment |
up vote
0
down vote
up vote
0
down vote
Something like will do the work:
A="file:///path/to/file"
B=$(echo $A|sed 's@/@@')
without g at the end in sed the program will change only first occurrence
Something like will do the work:
A="file:///path/to/file"
B=$(echo $A|sed 's@/@@')
without g at the end in sed the program will change only first occurrence
answered 3 hours ago
Romeo Ninov
4,57431626
4,57431626
add a comment |
add a comment |
up vote
0
down vote
Here is a cheat sheet for various way of doing that with some fundamentals.
https://devhints.io/bash
1
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Anthony Geoghegan
2 hours ago
add a comment |
up vote
0
down vote
Here is a cheat sheet for various way of doing that with some fundamentals.
https://devhints.io/bash
1
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Anthony Geoghegan
2 hours ago
add a comment |
up vote
0
down vote
up vote
0
down vote
Here is a cheat sheet for various way of doing that with some fundamentals.
https://devhints.io/bash
Here is a cheat sheet for various way of doing that with some fundamentals.
https://devhints.io/bash
answered 3 hours ago
SkyRar
467
467
1
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Anthony Geoghegan
2 hours ago
add a comment |
1
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Anthony Geoghegan
2 hours ago
1
1
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Anthony Geoghegan
2 hours ago
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Anthony Geoghegan
2 hours ago
add a comment |
hugovdd is a new contributor. Be nice, and check out our Code of Conduct.
hugovdd is a new contributor. Be nice, and check out our Code of Conduct.
hugovdd is a new contributor. Be nice, and check out our Code of Conduct.
hugovdd is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f480846%2fremoving-first-forward-slash-from-string%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password