Repetitive programming

By beppe

Hint for the lazy programmer. How many times did you need to make switches/If clauses/… with lots of conditions, maybe coming from the n-th field of a each line in a file?

You’re lucky: bash and awk are here to help. This example generates (brrr…) VB code:

#!/bin/bash
while read line
do
        echo "If variable = `echo $line | awk {'print $1;'}` Then " >> new_file
        echo "  boolean = True" >> new_file
        echo "End If" >> new_file
        echo " " >> new_file
done < file_to_read

Tags:

One Response to “Repetitive programming”

  1. ஸ்ரீராம் முரளி Says:

    wonderful.. thanks for the tip :)

Leave a Reply