It would likely help more if you could post some actual example lines, and show us where they need to be changed. Include examples of lines that should
not be matched, if there's any risk of catching the wrong ones.
And please use
[code][/code] tags around your code and data, to preserve formatting and to improve readability.
sed doesn't use "wildcards" (traditionally called
globbing in computer-ese), it uses
regular expressions, which are more complex and powerful, and have a different syntax.
In regex,
* means "zero or more of the previous character" (or expression), so "
:*" matches a string of colons of any length (including none). Also note that
* is what we call "greedy", which means that it will always try to match the longest string possible. In a simple case like this it may not be a problem, but it can be hard to control with more complex patterns.
Many, many computer tools support and use regex, so I
highly suggest you get online, find yourself a good regular expressions tutorial, and work your way through it. At the very least learn the basic level stuff. Here's a fairly decent guide to start you off:
http://www.grymoire.com/Unix/Regular.html
Anyway, to do what you want you first need to apply sed's "extended" regex option (
-r). Taking the description you gave, here are two possibilities, depending on how accurate you need it to be.
Code:
sed -r 's^1:[NY]:[0-9]{1,4}:ACAGTG^/2^'
I decided to use
^ as the delimiter.
[NY] means to match either a single
N or
Y. [..] is used to specify a list of possible characters that can exist at a position. Similarly...
[0-9]{1,4} means one to four digits. [0-9] means any digit, and {m,n} specifies the number of repeats of the previous match that are allowed (this is the part that requires the use of ext. regex).
So the above will match any number up to four digits long in the third field. However your description appears to state that the field can be
either a single
0,
or 2-4 digits of any kind. If this means that we have to avoid matching a single digit other than 0, then we have to be more cautious.
Code:
sed -r 's^1:[NY]:(0|[0-9]{2,4}):ACAGTG^/2^'
For this, I've grouped two possible choices together using
(|). That position can now be either 0, or it can be 2-4 digits. But it can't be a single non-zero digit.
Notice how effective use of regular expressions depends on you being able to clearly define the pattern to match. In particular you need to be able to state what exactly makes the section you want
different from the sections you don't want. So if what I gave doesn't suit your purposes, you'll need to come back with a more detailed explanation of what needs to be matched.