Repetitive programming

by

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

Advertisements

Tags:

One Response to “Repetitive programming”

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

    wonderful.. thanks for the tip 🙂

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


%d bloggers like this: