Seq command - revisited
posted 12 September 2006
I realised that I left out another crucial option for the seq command, that is the -f command. This is basically the formatting option, which allows you to format the results using the printf style floating-point FORMAT.
An example:
me@mycomp:~$
me@mycomp:~$ seq -f “line: %g” 1 5
line: 1
line: 2
line: 3
line: 4
line: 5
me@mycomp:~$ seq -f “line: %g” 1 5
line: 1
line: 2
line: 3
line: 4
line: 5
Now, with the option above, the practical side of it is now very obvious. Let’s say I want to generate a pool of test email address… ahh… you see it too eh!
Here we go:
me@mycomp:~$
me@mycomp:~$ seq -f “email_%g@example.com” 1 5
email_1@example.com
email_2@example.com
email_3@example.com
email_4@example.com
email_5@example.com
me@mycomp:~$ seq -f “email_%g@example.com” 1 5
email_1@example.com
email_2@example.com
email_3@example.com
email_4@example.com
email_5@example.com
Now, let’s generate this email list and have them separated by comma.
me@mycomp:~$
me@mycomp:~$ seq -s ‘,’ -f “email_%g@example.com” 1 5
me@mycomp:~$ mail_1@example.com,email_2@example.com,email_3@example.com,email_4@example.com,email_5@example.com
me@mycomp:~$ seq -s ‘,’ -f “email_%g@example.com” 1 5
me@mycomp:~$ mail_1@example.com,email_2@example.com,email_3@example.com,email_4@example.com,email_5@example.com
So… there you go, as promised, a nice and practical example of using the seq command. From now on, if you need a million sample emails in CSV format, just use the following:
me@mycomp:~$
me@mycomp:~$ seq -f “email_%g@example.com,firstname,lastname” 1 1000000 > emaillist.txt
me@mycomp:~$ seq -f “email_%g@example.com,firstname,lastname” 1 1000000 > emaillist.txt
You can also pipe them to other commands. Get creative!