replace zero with text using sed or awk

cha*_*has 1 awk sed

I have text file which looks like as shown below:

 0  chr23:54039     0   54039
 0  chr23:103278    0   103278
 0  chr22:174609    0   174609
 0  chr22:54039     0   54039
 0  chr25:103278    0   103278
 0  chr25:174609    0   174609
 26 chr26:174609    0   174609
Run Code Online (Sandbox Code Playgroud)

If the first column is '0' i need to replace the 0 in the first column with the number after chr. So, the output should look like:

23  chr23:54039     0   54039
23  chr23:103278    0   103278
22  chr22:174609    0   174609
22  chr22:54039     0   54039
25  chr25:103278    0   103278
25  chr25:174609    0   174609
26  chr26:174609    0   174609
Run Code Online (Sandbox Code Playgroud)

Can anyone provide a simple sed or awk any linux solution?

Jot*_*tne 6

如果第1列中的数字始终与chr数字相同,则可以执行此操作awk

awk '{split($2,a,":|chr");$1=a[2]}1' file
23 chr23:54039 0 54039
23 chr23:103278 0 103278
22 chr22:174609 0 174609
22 chr22:54039 0 54039
25 chr25:103278 0 103278
25 chr25:174609 0 174609
26 chr26:174609 0 174609
Run Code Online (Sandbox Code Playgroud)