Archive for the ‘awk’ Category

Repetitive programming

November 30, 2007

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:

while read line
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[/sourcecode]