Friday, March 03, 2017

I know, it's only AWKward, but I like it...


A nice little Awk program that generates git directories per language based on the contents of two files:

BEGIN {
    file="langs.txt"; 
    while((getline < file ) > 0 ) { 
        langs[$1] = 1  # record each language
    }   
}

/^$/ { }     # blank lines allowed

/^\;/ { }    # allows comments in the chapter file

/^[IVXCM]/ { } # skip the major section names

/^[0-9]/ {
    print $2
    for( lang in langs ) { 
        new_dir = lang "/" $2
        if (system( "[ -d " new_dir " ] ") == 0)
            print new_dir " already exists."
        else {
            print "We are going to add " new_dir
            if (system( "mkdir " new_dir) == 0) {
                system( "touch " new_dir "/README")
                system( "git add " new_dir "/README")    
            }   
        }   
    }   

}

No comments:

Post a Comment

Distraction Deterrents in Small Contexts

"distracted from distraction by distraction" - T.S. Eliot I've been reading a little on how Facebook and other social netwo...