Add string number to lines

So I have a file in the form

>
akdfvcnciejcndmdjfk
>
kdjkkkifjeeeeelfjfuf
>
fjfhchdejhfhfhfhfhfhf
>
skdkdhfhvnvncnccm

and I would like it to come out in the form

>1
akdfvcnciejcndmdjfk
>2
kdjkkkifjeeeeelfjfuf
>3
fjfhchdejhfhfhfhfhfhf
>4
skdkdhfhvnvncnccm

I think it would be possible with awk or sed, but not quite sure on how to implement it.

$ awk '{ if ($0 == ">") { print $0 n + 1; n++ } else { print } }' file
>1
akdfvcnciejcndmdjfk
>2
kdjkkkifjeeeeelfjfuf
>3
fjfhchdejhfhfhfhfhfhf
>4
skdkdhfhvnvncnccm
1 Like
awk '/>/{++c;$0=$0 c}1' file
1 Like

Thanks, you guys are the best.