I am learning how to use sed, and saw that I can use the =
to insert line numbers. However, this includes a newline:
file:
alpha
beta
gamma
running sed -n '=;p' file
:
1
alpha
2
beta
3
gamma
Is it possible, in a single call to sed, to insert these line numbers on the same line? So:
1 alpha
2 beta
3 gamma
I know that it is possible to do this with other tools, but I am wondering about the specific functionality of sed. Is there a way to append perhaps another regular-expression substitution after the =
to remove newlines?
This would be work for you.
sed '=' file | sed 'N; s/\n/ /'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With