Por que sed
é mais simples usando awk
?
awk -F_ '{printf "%s",; for(i=2;i<NF;i++){printf ":%s",$i}; printf "\%s\n",$NF}' your_input_file
E como você disse em um comentário? você precisa apenas de cada quarta linha
awk -F_ '(NR % 4) == 1 {printf "%s",; for(i=2;i<NF;i++){printf ":%s",$i}; printf "\%s\n",$NF; next} {print}' your_input_file
Exemplo
Arquivo de entrada
% cat foo
1_44567743346_567864_56788_5677_3
2_908798_08098_878_24332_24_24244_22
3_44567743346_567864_56788_5677_3
4_908798_08098_878_24332_24_24244_22
1_44567743346_567864_56788_5677_3
2_908798_08098_878_24332_24_24244_22
3_44567743346_567864_56788_5677_3
4_908798_08098_878_24332_24_24244_22
1_44567743346_567864_56788_5677_3
2_908798_08098_878_24332_24_24244_22
3_44567743346_567864_56788_5677_3
4_908798_08098_878_24332_24_24244_22
1_44567743346_567864_56788_5677_3
2_908798_08098_878_24332_24_24244_22
3_44567743346_567864_56788_5677_3
4_908798_08098_878_24332_24_24244_22
Saída de comando para alterar a cada quarta linha
% awk -F_ '(NR % 4) == 1 {printf "%s",; for(i=2;i<NF;i++){printf ":%s",$i}; printf "\%s\n",$NF; next} {print}' foo
1:44567743346:567864:56788:5677
2_908798_08098_878_24332_24_24244_22
3_44567743346_567864_56788_5677_3
4_908798_08098_878_24332_24_24244_22
1:44567743346:567864:56788:5677
2_908798_08098_878_24332_24_24244_22
3_44567743346_567864_56788_5677_3
4_908798_08098_878_24332_24_24244_22
1:44567743346:567864:56788:5677
2_908798_08098_878_24332_24_24244_22
3_44567743346_567864_56788_5677_3
4_908798_08098_878_24332_24_24244_22
1:44567743346:567864:56788:5677
2_908798_08098_878_24332_24_24244_22
3_44567743346_567864_56788_5677_3
4_908798_08098_878_24332_24_24244_22
Saída de comando para alterar cada linha
% awk -F_ '{printf "%s",; for(i=2;i<NF;i++){printf ":%s",$i}; printf "\%s\n",$NF}' foo
1:44567743346:567864:56788:5677
2:908798:08098:878:24332:24:24244
3:44567743346:567864:56788:5677
4:908798:08098:878:24332:24:24244
1:44567743346:567864:56788:5677
2:908798:08098:878:24332:24:24244
3:44567743346:567864:56788:5677
4:908798:08098:878:24332:24:24244
1:44567743346:567864:56788:5677
2:908798:08098:878:24332:24:24244
3:44567743346:567864:56788:5677
4:908798:08098:878:24332:24:24244
1:44567743346:567864:56788:5677
2:908798:08098:878:24332:24:24244
3:44567743346:567864:56788:5677
4:908798:08098:878:24332:24:24244