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
  • 223,850
  • 36
  • 205
  • 328
caesim
  • 37
  • 1
  • 8

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
  • 22,529
  • 3
  • 25
  • 46