Formatted command line argument -one liner- generator for testing CLI arguments validation

Reads from a column structured text file in which options are stored and creates a formatted output to be passed as command line arguments to some other program. Useful when testing many different possible arguments. Still, option names (-<name>) can be smartly fetched from somewhere else but right now I’m too lazy to do it.
bash-3.2$ cat test.dat
a b c d e f g h i
1 1 1 1 1 1 1 1 1
-1 -1 -1 -1 -1 -1 -1 -1 -1
1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1
-1.1 -1.1 -1.1 -1.1 -1.1 -1.1 -1.1 -1.1 -1.1
.1 .1 .1 .1 .1 .1 .1 .1 .1
-.1 -.1 -.1 -.1 -.1 -.1 -.1 -.1 -.1
-. -. -. -. -. -. -. -. -.
1. 1. 1. 1. 1. 1. 1. 1. 1.
-a -a -a -a -a -a -a -a -a
a a a a a a a a a
bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb
"" "" "" "" "" "" "" "" ""
0 0 0 0 0 0 0 0 0


bash-3.2$ while read line; do echo -e "$line" | awk '{print "-a " $1 " -b " $2 " -c " $3 " -d " $4 " -e " $5 " -f " $6 " -g " $7 " -h " $8 " -i " $9}'; done &lt; test.dat
-a a -b b -c c -d d -e e -f f -g g -h h -i i
-a 1 -b 1 -c 1 -d 1 -e 1 -f 1 -g 1 -h 1 -i 1
-a -1 -b -1 -c -1 -d -1 -e -1 -f -1 -g -1 -h -1 -i -1
-a 1.1 -b 1.1 -c 1.1 -d 1.1 -e 1.1 -f 1.1 -g 1.1 -h 1.1 -i 1.1
-a -1.1 -b -1.1 -c -1.1 -d -1.1 -e -1.1 -f -1.1 -g -1.1 -h -1.1 -i -1.1
-a .1 -b .1 -c .1 -d .1 -e .1 -f .1 -g .1 -h .1 -i .1
-a -.1 -b -.1 -c -.1 -d -.1 -e -.1 -f -.1 -g -.1 -h -.1 -i -.1
-a -. -b -. -c -. -d -. -e -. -f -. -g -. -h -. -i -.
-a 1. -b 1. -c 1. -d 1. -e 1. -f 1. -g 1. -h 1. -i 1.
-a -a -b -a -c -a -d -a -e -a -f -a -g -a -h -a -i -a
-a a -b a -c a -d a -e a -f a -g a -h a -i a
-a bbbbbbbbbb -b bbbbbbbbbb -c bbbbbbbbbb -d bbbbbbbbbb -e bbbbbbbbbb -f bbbbbbbbbb -g bbbbbbbbbb -h bbbbbbbbbb -i bbbbbbbbbb
-a "" -b "" -c "" -d "" -e "" -f "" -g "" -h "" -i ""
-a 0 -b 0 -c 0 -d 0 -e 0 -f 0 -g 0 -h 0 -i 0
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s