0

how can I add an incremental number in from of a list of strings?

example:

cat names.txt

alpha
beta
gamma

I need a loop, which inserts a number before the string.. like this

1. alpha
2. beta
3. gamma

could that be possible in bash?

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
caesim
  • 37
  • 1
  • 2
  • 9

1 Answers1

2

The command line util nl (= number lines) is made exactly for this:

nl -w 1 -s '. ' names.txt

prints

1. alpha
2. beta
3. gamma
Socowi
  • 25,550
  • 3
  • 32
  • 54