Sed command for replacements
Hi,
Does anyone know how I can replace ":" with "-" in linux?
I was able to remove the spaces and substitute them with ":", but now I need to remove one of the two ":" and replace it with a "-". For example:
1:12000000:13000000
into
1:12000000-13000000
I have tried it in several ways and it just brings everything back to empty spaces.
Thank you
• 1,354 views
•
link
2 answers
just sed
sed 's/:/-/2'
• 0 views
•
link
You can do this easily in awk:
$ echo "1:12000000:13000000" | awk '{split($0, a, ":"); print a[1]":"a[2]"-"a[3];}'
1:12000000-13000000
• 0 views
•
link
Log in to answer this question.
Hello maria333!
We believe that this post does not fit the main topic of this site.
This is a general question about sed use and not about bioinformatics. People have been kind enough to answer your query, but please don't post general questions about shell utilities here.
For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.
If you disagree please tell us why in a reply below, we'll be happy to talk about it.
Cheers!
Hi Daniel,
I was using sed to transform a chromosome position and I thought it was relevant since it's under a Linux environment.
Sorry if this is irrelevant.
Don't be too alarmed, we just try to keep the site on topic. Bioinformatics requires many skills, from programming to statistics, to command line Linux, but there are established communities elsewhere for all of those things, so questions that can fit generically into another site will be closed. It's not a judgement, just a gentle encouragement to keep things specifically about bioinformatics.
1:2000-3000 might look like a bioinformatics related term, but it's really just 3 numeric columns and two separators ;)