Use a variable counter in a bash one-liner

I had 70 different domain names that I need to add in a ssl cnf file for creating a certificate request.

The 70 different domain names was in a text file, one per line:

domainname1.something.com
domainname2.somehing.com
...

In order to create the alternative names list, I used this bash oneliner:

teller=1; for i in `cat /tmp/disse2`; do echo "DNS.$teller = $i"; teller=$((teller+1)); done

which then would give me:
DNS.1 = domainname1.something.com
DNS.2 = domainname2.somehing.com
...
DNS.70 = and-so-forth-until 70

This could be useful, if you have for instance hundreds or thousands of lines where you have to add a incremental value per line.

Leave a Reply

Your email address will not be published. Required fields are marked *