#!/usr/bin/awk -f
BEGIN {
	# Determines whether to print 'Unreleased' banner at top
	UNRELEASED_COMMITS = 1
	# Prefixes that determine whether a commit will be printed
	CHANGELOG_REGEX = "^(changelog|fix|docs|chore|feat): "
	FS="|"
	while ("git log --pretty='%D|%s|%H'" | getline) {
		IS_GIT_TAG = length($1) && match($1, /tag:/)
		if (IS_GIT_TAG) {
			UNRELEASED_COMMITS = 0
			# Cut out text up to tag
			sub(/.*tag: /, "", $1)
			# Cut out text after tag
			sub(/,.*/, "", $1)
			print $1
		} else {
			if ( UNRELEASED_COMMITS ) {
				print "Unreleased"
				UNRELEASED_COMMITS = 0
			}
			if ( match($2, CHANGELOG_REGEX) ) {
				sub(CHANGELOG_REGEX, "", $2)
				printf("\t- %s\n", $2)
			}
		}

	}
}

#!/usr/bin/awk -f
BEGIN {
	# Determines whether to print 'Unreleased' banner at top
	UNRELEASED_COMMITS = 1
	# Prefixes that determine whether a commit will be printed
	CHANGELOG_REGEX = "^(changelog|fix|docs|chore|feat|feature|refactor|update): "
	FS="|"
	while ("git log --pretty='%D|%s|%H'" | getline) {
		IS_GIT_TAG = length($1) && match($1, /tag:/)
		if (IS_GIT_TAG) {
			UNRELEASED_COMMITS = 0
			# Cut out text up to tag
			sub(/.*tag: /, "", $1)
			# Cut out text after tag
			sub(/,.*/, "", $1)
			print $1
		} else {
			if ( UNRELEASED_COMMITS ) {
				print "Unreleased"
				UNRELEASED_COMMITS = 0
			}
			if ( match($2, CHANGELOG_REGEX) ) {
				sub(CHANGELOG_REGEX, "", $2)
				printf("\t- %s\n", $2)
			}
		}

	}
}

feature: Add new prefixes: feature, refactor and update


# awk script to convert symbol export table formats

# converts an msvc .def file to an darwin ld export-symbols-list file
# we only support the most basic module definition syntax

# skip comments
/^\w*#.*/ {next}
/^\w*;.*/ {next}

# remember and propagate the library name
/LIBRARY/ {name = $2; print "\# export list for", name; next}

# skip various other lines
/^\w*NAME/ ||
/^\w*VERSION/ ||
/^\w*EXPORTS/ ||
/^\w*HEAPSIZE/ ||
/^\w*STACKSIZE/ ||
/^\w*STUB/ {next}

# todo: handle SECTIONS

# for symbols, strip the semicolon and mangle the name
/[a-zA-Z]+/ {sub(/\;/, ""); print "_" $1}

# todo: warn if we see publicname=privatename mappings
#       which other linkers don't support

# awk script to convert symbol export table formats

# converts an msvc .def file to an darwin ld export-symbols-list file
# we only support the most basic module definition syntax

# skip comments
/^\w*#.*/ {next}
/^\w*;.*/ {next}

# remember and propagate the library name
/LIBRARY/ {name = $2; print "# export list for", name; next}

# skip various other lines
/^\w*NAME/ ||
/^\w*VERSION/ ||
/^\w*EXPORTS/ ||
/^\w*HEAPSIZE/ ||
/^\w*STACKSIZE/ ||
/^\w*STUB/ {next}

# todo: handle SECTIONS

# for symbols, strip the semicolon and mangle the name
/[a-zA-Z]+/ {sub(/\;/, ""); print "_" $1}

# todo: warn if we see publicname=privatename mappings
#       which other linkers don't support

Remove a redundant escape character.

Remove a redundant escape character.

Some awks warn about it having no effect.

git-svn-id: 8dbf393e6e9ab8d4979d29f9a341a98016792aa6@16492 0101bb08-14d6-0310-b084-bc0e0c8e3800


# Print lines from a WebScraper csv file after joining extra newlines

# INVOCATION:
#   awk -f fixExtraLinesFrom-webscraper.awk BritBoxPrograms.csv

{
    if (/^"/)
        printf ("\n" $0)
    else
        printf
}

END {
    printf ("\n")
}

Make sure newline at end of file

Make sure newline at end of file


{
    if (1==NR)
    {
        startTimestamp = substr($1, 2, length($1) - 2)
        printf(";$FILEVERSION=1.3\n")
        printf(";$STARTTIME=%u.%u\n", mktime(strftime("%Y %m %d 0 0 0", startTimestamp)) / 86400 + 25569, \
                10000000000 / 86400 * (mktime(strftime("%Y %m %d %H %M %S", startTimestamp)) - mktime(strftime("%Y %m %d 0 0 0", startTimestamp))))
        currentTimeOffset = 0.0
    }
    else
    {
        previousTimeOffset = currentTimeOffset
        currentTimestamp = substr($1, 2, length($1) - 2)
        currentTimeOffset = currentTimestamp - startTimestamp
        if (currentTimeOffset < 0)
        {
            startTimestamp = currentTimestamp + currentTimeOffset
            currentTimeOffset = previousTimeOffset
        }
    }
    printf("%u) %.3f 1 Rx %s - %s", NR, currentTimeOffset * 1000, $3, substr($4, 2, length($4) - 2))
    if (5<=NF)
    {
        for(i=5;i<=NF;i++)
        {
            printf " "$i
        }
    }
    printf "\n"
}

{
    if (1==NR)
    {
        startTimestamp = substr($1, 2, length($1) - 2)
        printf(";$FILEVERSION=1.3\n")
        printf(";$STARTTIME=%u.%.0f\n", mktime(strftime("%Y %m %d 0 0 0", startTimestamp)) / 86400 + 25569, \
                10000000000.0 / 86400.0 * (mktime(strftime("%Y %m %d %H %M %S", startTimestamp)) - mktime(strftime("%Y %m %d 0 0 0", startTimestamp))))
        printf(";\n; Start time: %s\n", startTimestamp)
        printf(";             %u\n", mktime(strftime("%Y %m %d %H %M %S", startTimestamp)))
        printf(";             %s\n;\n", strftime("%Y-%m-%dT%H:%M:%S%z (%Z)", startTimestamp))
        currentTimeOffset = 0.0
    }
    else
    {
        previousTimeOffset = currentTimeOffset
        currentTimestamp = substr($1, 2, length($1) - 2)
        currentTimeOffset = currentTimestamp - startTimestamp
        if (currentTimeOffset < 0)
        {
            startTimestamp = currentTimestamp + currentTimeOffset
            currentTimeOffset = previousTimeOffset
        }
    }
    printf("%u) %.3f 1 Rx %s - %s", NR, currentTimeOffset * 1000, $3, substr($4, 2, length($4) - 2))
    if (5<=NF)
    {
        for(i=5;i<=NF;i++)
        {
            printf " "$i
        }
    }
    printf "\n"
}

Use float for calculating fractional part of STARTTIME to support busybox awk.
Also print used start time is various representations.

Compared to gawk, busybox awk does only support 32 bit integers.


#!/usr/bin/awk -f
BEGIN {
	# Determines whether to print 'Unreleased' banner at top
	UNRELEASED_COMMITS = 1
	# Prefixes that determine whether a commit will be printed
	CHANGELOG_REGEX = "^(changelog|fix|docs|chore|feat|feature|refactor|update): "
	FS="|"
	while ("git log --pretty='%D|%s|%H'" | getline) {
		IS_GIT_TAG = length($1) && match($1, /tag:/)
		if (IS_GIT_TAG) {
			UNRELEASED_COMMITS = 0
			# Cut out text up to tag
			sub(/.*tag: /, "", $1)
			# Cut out text after tag
			sub(/,.*/, "", $1)
			print $1
		} else {
			if ( UNRELEASED_COMMITS ) {
				print "Unreleased"
				UNRELEASED_COMMITS = 0
			}
			if ( match($2, CHANGELOG_REGEX) ) {
				sub(CHANGELOG_REGEX, "", $2)
				printf("\t- %s\n", $2)
			}
		}

	}
}

#!/usr/bin/awk -f
BEGIN {
	REPO_URL = getRepoURL()
	# Prefixes that determine whether a commit will be printed
	CHANGELOG_REGEX = "^(changelog|fix|docs|chore|feat|feature|refactor|update): "
	FS="|"
	# %D: tags
	# %s: commit message
	# %H: long hash
	# %h: short hash
	while ("git log --pretty='%D|%s|%H|%h'" | getline) {
		IS_GIT_TAG = length($1) && match($1, /tag:/)
		if (IS_GIT_TAG) {
			printTag($1)
		} else {
			printCommit($2, $3, $4)
		}

	}
}
function printTag(input) {
	# Cut out text up to tag
	sub(/.*tag: /, "", input)
	# Cut out text after tag
	sub(/,.*/, "", input)
	printf("## %s\n", input)
}
function printCommit(input, longHash, shortHash) {
	if ( match(input, CHANGELOG_REGEX) ) {
		sub(CHANGELOG_REGEX, "", input)
		printf("- %s (%s)\n", input, makeCommitLink(REPO_URL, shortHash, longHash) )
	}
}
function makeCommitLink(repoUrl, shortHash, longHash) {
	return ("[" shortHash "](" repoUrl "/commit/" longHash ")")
}
# Get Git repo URL
function getRepoURL() {
	"git config --get remote.upstream.url || git config --get remote.origin.url || git config --get remote.dev.url" | getline REPO_URL
	sub(/:/, "/", REPO_URL)
	sub(/git@/, "https://", REPO_URL)
	sub(/\.git/, "", REPO_URL)
	return REPO_URL
}

Update to output in markdown format

feat: Update to output in markdown format


#!/usr/bin/env awk -f
#
# Computes the median.
#
# Usage: median
#
# Input:
#   - a column of numbers
#
# Output:
#   - median value

BEGIN {
	i = 0
}
{
	a[i++] = $1
}
END {
	j = i/2
	if ( i%2 == 1 ) {
		median = a[int(j)]
	} else {
		median = (a[j] + a[j-1])/2
	}
	print median
}

#!/usr/bin/env awk -f
#
# Computes the median.
#
# Usage: median
#
# Input:
#   - a sorted column of numbers
#
# Output:
#   - median value

BEGIN {
	i = 0
}
{
	a[i++] = $1
}
END {
	j = i/2
	if ( i%2 == 1 ) {
		median = a[int(j)]
	} else {
		median = (a[j] + a[j-1])/2
	}
	print median
}

Clarify that input must be sorted

Clarify that input must be sorted


BEGIN {
    FS = "\n";
}

/Targets:/ {
    while (getline && $0 != "") {
        if ($0 ~ /Tests/) continue;

        sub(/^ +/, "");
        print;
    }
}

BEGIN {
    FS = "\n";
}

/Targets:/ {
    while (getline && $0 != "") {
        if ($0 ~ /Test/) continue;

        sub(/^ +/, "");
        print;
    }
}

Exclude any target with "Test" in the name


#!/usr/bin/awk
#
# Patch the generated wrapper Swift code to handle special cases
#
BEGIN { depr_init = 0 }
/open .* ColorSelection/ { depr_init = 1 }
/public .* ColorSelection/ { depr_init = 1 }
/public .* HSV/ { depr_init = 1 }
/open .* HSV/ { depr_init = 1 }
/ init.. {/ {
	if (depr_init) {
		printf("@available(*, deprecated) ")
		depr_init = 0
	}
}
/ init. title:/ {
	if (depr_init) {
		printf("@available(*, deprecated) ")
		depr_init = 0
	}
}
// { print }

#!/usr/bin/awk
#
# Patch the generated wrapper Swift code to handle special cases
#
BEGIN { depr_init = 0 ; comment = 0 }
/open .* ColorSelection/ { depr_init = 1 }
/public .* ColorSelection/ { depr_init = 1 }
/public .* HSV/ { depr_init = 1 }
/open .* HSV/ { depr_init = 1 }
/open .* HSV/ { depr_init = 1 }
/func getColumnHeaderCells/ { comment = 1 }
/func getRowHeaderCells/ { comment = 1 }
/ init.. {/ {
	if (depr_init) {
		printf("@available(*, deprecated) ")
		depr_init = 0
	}
}
/ init. title:/ {
	if (depr_init) {
		printf("@available(*, deprecated) ")
		depr_init = 0
	}
}
// {
	if (comment) {
		printf("// ")
	}
	print
}
/^    }$/ { comment = 0 }

Make this link against gtk+-3.24.4

Make this link against gtk+-3.24.4


BEGIN {
	print "V1.0 {";
	print "    global:";
}
{
	# Remove the CR character in case the sources are mapped from
	# a Windows share and contain CRLF line endings
	gsub(/\r/,"", $0);

	# Skip empty lines and comment lines starting with semicolon
	if (NF && !match($0, /^[[:space:]]*;/))
	{
		print "        "  $0 ";";
	}
}
END {
	print "    local: *;"
	print "};";
}

BEGIN {
	print "V1.0 {";
	print "    global:";
}
{
	# Remove the CR character in case the sources are mapped from
	# a Windows share and contain CRLF line endings
	gsub(/\r/,"", $0);

	# Skip empty lines and comment lines starting with semicolon
	if (NF && !match($0, /^[:space:]*;/))
	{
		print "        "  $0 ";";
	}
}
END {
	print "    local: *;"
	print "};";
}

Revert "Fix bracket expression matches a character at gawk"


Include header files whose path begins with ../ .

git-svn-id: 12ae5aeef08fd453d75833463da4cc20df82a94e@2159 8af8166b-12a6-a448-a533-9086ace3f9f6


BEGIN{
        now = systime()
        format = "%Y/%m/%d %H:%M:%S"

}
{
        split($1, DATE, "/")
        split($2, TIME, ":")
        $1 = ""
        $2 = ""
        t = mktime(DATE[1] " " DATE[2] " " DATE[3] " " TIME[1] " " TIME[2] " " TIME[3])
        if (delta == "") {
                delta = now - t
        }
        print strftime(format, t + delta) $0
}

BEGIN{
        now = systime()
        format = "%Y/%m/%d %H:%M:%S"

}
{
        split($1, DATE, "/")
        split($2, TIME, ":")
        t = mktime(DATE[1] " " DATE[2] " " DATE[3] " " TIME[1] " " TIME[2] " " TIME[3])
        if (delta == "") {
                delta = now - t
        }
        out = strftime(format, t + delta)
        for (i = 3; i <= NF; i++) {
                out = out OFS $i
        }
        print out
}

Fix an output formatting bug in the rewriter script.


BEGIN{doit = 0}
 { if (doit) print $0 }
 $0 == "%%EndSetup" { doit = 1 }

BEGIN{doit = 0}
 { if (doit) print $0 }
 $0 = /%%End.*Setup/ { doit = 1 }

Fix awk script to work with cairo generated postscript


#!/usr/bin/awk -f

BEGIN { FS = "," }

$1 == "pld" { p += $2 }
$1 == "val" { v += $2 }
{ "date -d "$3" +%B" | getline month
  monthly[month][$1] += $2
  categorically[$1][$4] += $2 }

END { print "Val spent "v"€"
      print "PLD spent "p"€"
      if ( p < v )
        print "PLD owe "v - p"€ to val."
      else if ( p > v )
        print "Val owe "p - v"€ to PLD."
      else
        print "Accounts are balanced."

      print ""

      if ( verbose == 1 ) {
        print "Here's the detail:"

        print "  Spendings per month:"
        for ( month in monthly ) {
          print "    In "month":"
          for ( who in monthly[month] ) {
            print "      "who" spent "monthly[month][who]"€."
          }
        }

        print "  Spendings by category:"
        for ( who in categorically ) {
          print "    By "who":"
          for ( category in categorically[who] ) {
            print "      "categorically[who][category]"€ in "category"."
          }
        }
      }
    }

#!/usr/bin/awk -f

BEGIN { FS = "," }

$1 == "pld" { p += $2 }
$1 == "val" { v += $2 }
{ "date -d "$3" '+%B %Y'" | getline month_and_year
  monthly[month_and_year][$1] += $2
  categorically[$1][$4] += $2 }

END { print "Val spent "v"€"
      print "PLD spent "p"€"
      if ( p < v )
        print "PLD owe "v - p"€ to val."
      else if ( p > v )
        print "Val owe "p - v"€ to PLD."
      else
        print "Accounts are balanced."

      print ""

      if ( verbose == 1 ) {
        print "Here's the detail:"

        print "  Spendings per month:"
        for ( month_and_year in monthly ) {
          print "    In "month_and_year":"
          total_for_month = 0
          for ( who in monthly[month_and_year] ) {
            spent = monthly[month_and_year][who]
            print "      "who" spent "spent"€."
            total_for_month += spent
          }
          print "      Total: "total_for_month"€."
        }

        print "  Spendings by category:"
        for ( who in categorically ) {
          print "    By "who":"
          for ( category in categorically[who] ) {
            print "      "categorically[who][category]"€ in "category"."
          }
        }
      }
    }

Add year differentation into monthly report


#
# Parsing output of:
#
# hdfs dfs -du -s '/user/*'
#

function dbstr(s) {
	if (s) { return "'" s "'" }
	else { return "NULL" }
}

function dbi(i) {
	if (i >= 0) { return i }
	else { return "NULL" }
}

BEGIN {
	FS="[ \t/]+"
	print "INSERT INTO measure (name) VALUES ('quota');";
}

{
	used=$1
	user=$4
	print "INSERT INTO quota (id_measure, user, used) VALUES (last_insert_id(), " dbstr(user) ", " dbi(used) ");"
}

#
# Parsing output of:
#
# hdfs dfs -du -s '/user/*'
#

function dbstr(s) {
	if (s) { return "'" s "'" }
	else { return "NULL" }
}

function dbi(i) {
	if (i >= 0) { return i }
	else { return "NULL" }
}

BEGIN {
	FS="[ \t/]+"
	print "INSERT INTO measure (name) VALUES ('quota');";
}

/^[0-9]+[ 	]+[0-9]+[ 	]+\/.*/ {
	used=$1
	user=$4
	print "INSERT INTO quota (id_measure, user, used) VALUES (last_insert_id(), " dbstr(user) ", " dbi(used) ");"
}
/^[0-9]+[ 	]+\/.*/ {
	used=$1
	user=$3
	print "INSERT INTO quota (id_measure, user, used) VALUES (last_insert_id(), " dbstr(user) ", " dbi(used) ");"
}

Support also different version of Hadoop (=Fedora).


{
    title = $0
    if (match (title, /, The"$/)) {
        sub (/^"/,"\"The ", title)
        sub (/, The"$/,"\"", title)
    }
    printf ("echo ==\\> %3d: %s\n",NR,title) >> TITLES_SCRIPT
    printf ("./getIMDbInfoFrom-titles.py %s\n",title) >> TITLES_SCRIPT
    printf ("echo \n\n") >> TITLES_SCRIPT

    printf ("echo ==\\> %3d: %s\n",NR,title) >> ID_SCRIPT
    printf ("./getIMDb_IDsFrom-titles.py %s | head -7\n",title) >> ID_SCRIPT
    printf ("echo \n\n") >> ID_SCRIPT
}

{
    title = $0
    if (match (title, /, The"$/)) {
        sub (/^"/,"\"The ", title)
        sub (/, The"$/,"\"", title)
    }

    if (FILENAME ~ /Acorn/)
        KEY = "A"
    if (FILENAME ~ /BBox/)
        KEY = "B"
    if (FILENAME ~ /MHz/)
        KEY = "M"
    if (FILENAME ~ /Watched/)
        KEY = "W"

    printf ("echo ==\\> %sT %3d: %s\n", KEY, NR, title) >> TITLES_SCRIPT
    printf ("./getIMDbInfoFrom-titles.py %s\n",title) >> TITLES_SCRIPT
    printf ("echo \n\n") >> TITLES_SCRIPT

    printf ("echo ==\\> %sI %3d: %s\n", KEY, NR, title) >> ID_SCRIPT
    printf ("./getIMDb_IDsFrom-titles.py %s | head -7\n",title) >> ID_SCRIPT
    printf ("echo \n\n") >> ID_SCRIPT
}

Add identifier KEY so we can see where we are in -v script


BEGIN {
  session_count = 0;
  FS="|"
  OFS="|"
}

{
  if ($3 ~ "[0-9]+") {
    # See if the current line is already in the table
    frame_file = destDir "/frames/Frame"$3".html"
    session_line = ""
    "grep -i \"" session_token "\" " frame_file | getline session_line

    if (session_line == "" ) {
      $6 = "{0}"
      print $0

    } else {
      found = 0;
      split(session_line, array, " ")
      session = array[2]
      for (i=0; i < session_count; i++) {
        if (sessions[i] == session) {
          found = 1
          $6 = "{" i+1 "}"
          print $0
          break
        }
      }

      if (found == 0) {
        $6 = "{" session_count+1 "}"
        sessions[session_count++] = session
        print $0
        s = sprintf("echo '%2d: new session in frame %4s: %s' >&2", session_count, $3, session)
        system(s)
      }
    }

  } else {
    # Comment line, line starting with "#".
    # Requires no processing, just print it
    print $0
  }
}

BEGIN {
  session_count = 0;
  FS="|"
  OFS="|"
}

{
  if ($3 ~ "[0-9]+") {
    # See if the current line is already in the table
    frame_file = destDir "/frames/Frame"$3".html"
    session_line = ""
    "grep -i \"" session_token "\" " frame_file | getline session_line
    close(grep)

    if (session_line == "" ) {
      $6 = "{0}"
      print $0

    } else {
      found = 0;
      split(session_line, array, " ")
      session = array[2]
      for (i=0; i < session_count; i++) {
        if (sessions[i] == session) {
          found = 1
          $6 = "{" i+1 "}"
          print $0
          break
        }
      }

      if (found == 0) {
        $6 = "{" session_count+1 "}"
        sessions[session_count++] = session
        print $0
        s = sprintf("echo '%2d: new session in frame %4s: %s' >&2", session_count, $3, session)
        system(s)
      }
    }

  } else {
    # Comment line, line starting with "#".
    # Requires no processing, just print it
    print $0
  }
}

Add a close command to avoid too many files opened problems (encountered with large libpcap file)

git-svn-id: 392d0e5ce652024192c571322d40dcc23d6d83b0@118 8a65f31f-a56f-4bd6-98e8-2755f64920ec


###############################################################################
# BRLTTY - A background process providing access to the console screen (when in
#          text mode) for a blind person using a refreshable braille display.
#
# Copyright (C) 1995-2006 by The BRLTTY Developers.
#
# BRLTTY comes with ABSOLUTELY NO WARRANTY.
#
# This is free software, placed under the terms of the
# GNU General Public License, as published by the Free Software
# Foundation.  Please see the file COPYING for details.
#
# Web Page: http://mielke.cc/brltty/
#
# This software is maintained by Dave Mielke <dave@mielke.cc>.
###############################################################################

/#define[ \t]*BRLAPI_KEY_[A-Z_]+_MASK/ {
  apiMask(substr($2, 12), $2, getDefineValue(), "")
  next
}

/#define[ \t]*BRLAPI_KEY_[A-Z_]+_SHIFT/ {
  apiShift(substr($2, 12), $2, getDefineValue(), "")
  next
}

/#define[ \t]*BRLAPI_KEY_TYPE_/ {
  apiType(substr($2, 17), $2, getDefineValue(), "")
  next
}

/#define[ \t]*BRLAPI_KEY_SYM_/ {
  apiKey(substr($2, 16), $2, getDefineValue(), "")
  next
}

###############################################################################
# BRLTTY - A background process providing access to the console screen (when in
#          text mode) for a blind person using a refreshable braille display.
#
# Copyright (C) 1995-2006 by The BRLTTY Developers.
#
# BRLTTY comes with ABSOLUTELY NO WARRANTY.
#
# This is free software, placed under the terms of the
# GNU General Public License, as published by the Free Software
# Foundation.  Please see the file COPYING for details.
#
# Web Page: http://mielke.cc/brltty/
#
# This software is maintained by Dave Mielke <dave@mielke.cc>.
###############################################################################

/#define[ \t]*BRLAPI_KEY_MAX/ {
  apiMask(substr($2, 12), $2, getDefineValue(), "")
  next
}

/#define[ \t]*BRLAPI_KEY_[A-Z_]+_MASK/ {
  apiMask(substr($2, 12), $2, getDefineValue(), "")
  next
}

/#define[ \t]*BRLAPI_KEY_[A-Z_]+_SHIFT/ {
  apiShift(substr($2, 12), $2, getDefineValue(), "")
  next
}

/#define[ \t]*BRLAPI_KEY_TYPE_/ {
  apiType(substr($2, 17), $2, getDefineValue(), "")
  next
}

/#define[ \t]*BRLAPI_KEY_SYM_/ {
  apiKey(substr($2, 16), $2, getDefineValue(), "")
  next
}

Define KEY_MAX for Python. (dm)

Define KEY_MAX for Python. (dm)

git-svn-id: 30a5f035a20f1bc647618dbad7eea2a951b61b7c@2776 91a5dbb7-01b9-0310-9b5f-b28072856b6e


#!/usr/bin/awk -f
#
# Adds github compatible labels to level 1 and 2 markdown headings
# in underline style.
#

#
# Substitute github references with doxygen references.
#
/\(#[_a-z0-9-]*\)/ {
	gsub(/\(#[_a-z0-9-]*\)/, "<__REF__&__REF__>")
	gsub(/<__REF__\(#/, "(@ref ")
	gsub(/\)__REF__>/, ")")
}

#
# If this line is underlining a heading, add a label to the previous
# line.
#
line && (/^===*$/ || /^---*$/) {
	id = tolower(line)
	gsub(/[^_a-z0-9]+/, "-", id)
	line = line " {#" id "}"
}

#
# Print the previous line, after a label might have been added.
#
{print line}

#
# Remember this line when scanning the next one for underlining.
#
{line = $0}

#
# Print the last line.
#
END { print }

#!/usr/bin/awk -f
#
# Adds github compatible labels to level 1 and 2 markdown headings
# in underline style.
#

#
# Get file name prefix for references.
#
filename != FILENAME {
	filename = FILENAME
	# strip path
	"pwd" | getline path
	path = path "/"
	prefix = substr(filename, 1, length(path)) == path \
	         ? substr(filename, length(path) + 1) \
	         : filename
	sub(/\.[^.]*$/, "", prefix)
	gsub(/[^_a-z0-9]+/, "-", prefix)
	prefix = "md_" prefix "_"
}

#
# Substitute github references with doxygen references.
#
/\(#[_a-z0-9-]*\)/ {
	gsub(/\(#[_a-z0-9-]*\)/, "<__REF__&__REF__>")
	gsub(/<__REF__\(#/, "(@ref " prefix)
	gsub(/\)__REF__>/, ")")
}

#
# If this line is underlining a heading, add a label to the previous
# line.
#
line && (/^===*$/ || /^---*$/) {
	id = tolower(line)
	gsub(/[^_a-z0-9]+/, "-", id)
	line = line " {#" prefix id "}"
}

#
# Print the previous line, after a label might have been added.
#
{print line}

#
# Remember this line when scanning the next one for underlining.
#
{line = $0}

#
# Print the last line.
#
END { print }

Use a file name prefix for generated labels

This ensures labels are unique within the wider context of the doxygen
documentation.


BEGIN {
}

function extension(str){
  n = split(str, parts, ".")
  if (n == 1){
    return "<NO EXTENSION>"
  } else {
    return parts[n]
  }
}

$2 != "total" {
  by_type[extension($2)] += $1
}

$2 ~ "CMakeLists.txt" {
  #cmake should not count as text
  by_type["txt"] -= $1
  by_type["cmake"] += $1
}

$2 ~ "test" {
  by_type[extension($2)] -= $1
  by_type["TEST"] += $1
}

END {

  # join up cpp types
  by_type["cpp"] += by_type["hpp"]
  delete by_type["hpp"]

  #get rid of some filetypes I dont care about
  delete by_type["gitignore"]
  delete by_type["jpg"]
  delete by_type["png"]
  delete by_type["ttf"]
  delete by_type["pdf"]

  #print each extension, collect the total
  total=0
  for (x in by_type) {
    if (by_type[x] > 0) {
      total += by_type[x]
      print (x, by_type[x])
    }
  }

  print("Total:", total)
}

BEGIN {
}

function getExtension(str){
  n = split(str, parts, ".")
  if (n == 1){
    return "<NO EXTENSION>"
  } else {
    return parts[n]
  }
}

$2 != "total" {
  by_type[getExtension($2)] += $1
}

$2 ~ "CMakeLists.txt" {
  #cmake should not count as text
  by_type["txt"] -= $1
  by_type["cmake"] += $1
}

$2 ~ "test" {
  by_type[getExtension($2)] -= $1
  by_type["TEST"] += $1
}

END {

  # join up cpp types
  by_type["cpp"] += by_type["hpp"]
  delete by_type["hpp"]

  #get rid of some filetypes I dont care about
  delete by_type["gitignore"]
  delete by_type["jpg"]
  delete by_type["png"]
  delete by_type["ttf"]
  delete by_type["pdf"]

  #print each getExtension, collect the total
  total=0
  for (x in by_type) {
    if (by_type[x] > 0) {
      total += by_type[x]
      print (x, by_type[x])
    }
  }

  print("Total:", total)
}

Fix an awk script that doesn't seem to be very portable


{ content = $1 ~ /^(content|skin|locale)$/ }
content && $NF ~ /^[a-z]/ { $NF = "/" name "/" $NF }
content {
    sub(/^\.\./, "", $NF);
    $NF = "jar:chrome/" name ".jar!" $NF
}
{
    sub("^\\.\\./liberator/", "", $NF)
    print
}

{ content = $1 ~ /^(content|skin|locale)$/ }
content && $NF ~ /^[a-z]/ { $NF = "/" name "/" $NF }
content {
    sub(/^\.\./, "", $NF);
    $NF = "jar:chrome/" name ".jar!" $NF
}
{
    sub("^\\.\\./common/", "", $NF)
    print
}

Fix the modules path in the xpi chrome.manifests


# Generate MHz_TV_Shows_minutes.csv by processing  SHORT_SPREADSHEET to figure
# average episode length
#

BEGIN {
    FS = "\t"
}

/^Title/ {
    printf ("%s\t%s\t%s\t%s\tAvg Len\t%s\t%s\t%s\t%s\t%s\n",
            $1,$2,$3,$4,$5,$6,$7,$8,$9)
}

/=HYPERLINK/ {
    dur=$4
    sub (/h/,"",dur)
    sub (/m/,"",dur)
    split (dur,fld," ")
    eplen = (fld[1]*60+fld[2])/$3
    printf ("%s\t%s\t%s\t%s\t%d\t%s\t%s\t%s\t%s\t%s\n",
            $1,$2,$3,$4,eplen,$5,$6,$7,$8,$9)
}

/^Non-blank values/ || /^Total seasons & episodes/ { print }

Print last two lines in Avg

Print last two lines in Avg


BEGIN {
	print "V1.0 {";
	print "    global:";
}
{
	# Remove the CR character in case the sources are mapped from
	# a Windows share and contain CRLF line endings
	gsub(/\r/,"", $0);

	# Skip empty lines and comment lines starting with semicolon
	if (NF && !match($0, /^[:space:]*;/))
	{
		print "        "  $0 ";";
	}
}
END {
	print "    local: *;"
	print "};";
}

BEGIN {
	print "V1.0 {";
	print "    global:";
}
{
	# Remove the CR character in case the sources are mapped from
	# a Windows share and contain CRLF line endings
	gsub(/\r/,"", $0);

	# Skip empty lines and comment lines starting with semicolon
	if (NF && !match($0, /^[ \t]*;/))
	{
		print "        "  $0 ";";
	}
}
END {
	print "    local: *;"
	print "};";
}

Handle mscorwks_unixexports.src with better regexp operator for compatibility

ver3:
According to the gawk manual, The '\S' operator (as shorthand for '[^[:space:]]')
matches any character that is not whitespace. However, '[ \t]' is better than
'\S' for Mac OSX.
(source - https://www.gnu.org/software/gawk/manual/html_node/GNU-Regexp-Operators.html )

ver2:
With ver1, the build-break is caused by different awk versions (by @jkotas).
(Revert PR - https://github.com/dotnet/coreclr/pull/4005)
To resolve the limitation of the ver1, @janvorli proposed that the
\S expression is better than [:space:] for the most compatible solution.

There are a lot of different AWK software (e.g. awk, gawk, mawk, nawk, etc)
and versions among the popular Linux distributions. This patch is a simply
way to handle 'mscorwks_unixexports.src' file with \S operator for more
compatibility amon the different awk versions.

ver1:
It's must be modified by gawk implementation that check it exactly
as a plain character (e.g., space, alnum) within the bracket expression
at ./coreclr/generateversionscript.awk. The [[:space:]] is more appropriate than
the [:space:]]. (PR - https://github.com/dotnet/coreclr/pull/3943)

Signed-off-by: Geunsik Lim <acd8f4539166019ed6425de5f67e6d834f46e5a4@samsung.com>
Signed-off-by: MyungJoo Ham <84146178f7c201fa3079bfc93fccba71d81dffe3@samsung.com>
Signed-off-by: Prajwal A N <b9045b1f56dab106e820d6cda13049bcd6c9e3af@samsung.com>


#
# Converts the output of 'nm' into a C source containing an array of symbols
# that correspond to functions (t and T in terms of 'nm').
#
# Usage:
#   nm -n image | awk -f nm2c.awk
#
#   Date: Aug 28, 2012
# Author: Eldar Abusalimov
#

BEGIN {
	print "/* Auto-generated file. Do not edit. */";
	print "";
	print "#include <debug/symbol.h>";
	print "#include <stddef.h>";
	print "";
	print "const struct symbol __symbol_table[] = {";
}

/^[0-9a-fA-F]* [tT]/ {
	printf "\t{ (void *) 0x%s, \"%s\" },\n", $1, $3;
}

END {
	print "};";
	print "const size_t __symbol_table_size =";
	print "\tsizeof(__symbol_table) / sizeof(__symbol_table[0]);";
	print "";
}

#
# Converts the output of 'nm' into a C source containing an array of symbols
# that correspond to functions (t and T in terms of 'nm').
#
# Usage:
#   nm -n image | awk -f nm2c.awk
#
#   Date: Aug 28, 2012
# Author: Eldar Abusalimov
#

BEGIN {
	print "/* Auto-generated file. Do not edit. */";
	print "";
	print "#include <debug/symbol.h>";
	print "#include <stddef.h>";
	print "";
	print "const struct symbol __symbol_table[] = {";
}

/^[0-9a-fA-F]* [tT]/ {
	split($0,a," [tT] ");
	printf "\t{ (void *) 0x%s, \"%s\" },\n", $1, a[2];
}

END {
	print "};";
	print "const size_t __symbol_table_size =";
	print "\tsizeof(__symbol_table) / sizeof(__symbol_table[0]);";
	print "";
}

c++: Fix for symbol table demangled names with spaces


BEGIN {
    FS="\n"
    OFS=""
    ORS="\n"
    print "#!/bin/sh"
    print " "
}
# blank lines
/^$/ { next }
# record header
$1 ~ /^\*\*\*\*/ {
    next
}
# summary field
$1 ~ /^[ ]*summary\:/ {
    gsub(/\r/,"");
    idx = match($1, /summary\:(.*)/)
    print "SUMMARY=\"" substr($1, idx + 9) "\""
    next
}
# startdate field
$1 ~ /^[ ]*startdate\: / {
    match($1, /startdate\: /)
    print "STARTDATE=\"`date -d '" substr($1, RSTART + RLENGTH) "-000' '+%a %e %b %R'`\""
    next
}
# vcalendar start tag
$1 ~ /^[ ]*calendardata\: / {
    gsub(/\r/,"");
    match($1, /calendardata\: /)
    print "echo \"" substr($1, RSTART + RLENGTH) "\" >event.ics"
    next
}
# vcalendar end tag
$1 ~ /^END\:VCALENDAR/ {
    gsub(/\r/,"");
    print "echo \"" $1 "\" >>event.ics"
    print "mpack -s \"$SUMMARY - $STARTDATE\" event.ics $1"
    print ""
    next
}
# vcalendar body
{
    gsub(/\r/,"");
    print "echo \"" $0 "\" >> event.ics"
}

BEGIN {
    FS="\n";
    OFS="";
    ORS="\n";
    print "#!/bin/sh";
    print "#";
}
# blank lines
/^$/ {
    next;
}
# record header
$1 ~ /^\*\*\*\*/ {
    next;
}
# summary field
$1 ~ /^[ ]*summary\:/ {
    gsub(/\r/,"");
    idx = match($1, /summary\:(.*)/);
    print "SUMMARY=\"" substr($1, idx + 9) "\"";
    next;
}
# startdate field
$1 ~ /^[ ]*startdate\: / {
    match($1, /startdate\: /);
    print "STARTDATE=\"`date -d '" substr($1, RSTART + RLENGTH) "-000' '+%a %e %b %R'`\"";
    next;
}
# vcalendar start tag
$1 ~ /^[ ]*calendardata\: / {
    gsub(/\r/,"");
    match($1, /calendardata\: /);
    print "ICS=$(mktemp --suffix=.ics)";
    print "cat > \"${ICS}\" <<EOF";
    print substr($1, RSTART + RLENGTH);
    next;
}
# vcalendar end tag
$1 ~ /^END\:VCALENDAR/ {
    gsub(/\r/,"");
    print $1;
    print "EOF";
    print "mpack -s \"$SUMMARY - $STARTDATE\" \"${ICS}\" $1";
    print "#";
    next;
}
# vcalendar body
{
    gsub(/\r/,"");
    print $0;
}

Improve shell script (thx 'Barmic')

Improve shell script (thx 'Barmic')


#!/usr/bin/awk -f
BEGIN {
    FS = OFS = "\t";
}
{
    len = split($3, words, ", ");

    if (length(N) > 0 && len >= N) next;

    for (i = 1; i <= len - 1; i++) {
        for (j = i + 1; j <= len; j++) {
            print words[i], words[j], ORS, words[j], words[i] | "sort --parallel=$(nproc) -us";
        }
    }
}

#!/usr/bin/awk -f
BEGIN {
    FS  = "\t";
    OFS = "";
}
{
    len = split($3, words, ", ");

    if (length(N) > 0 && len >= N) next;

    for (i = 1; i <= len - 1; i++) {
        for (j = i + 1; j <= len; j++) {
            print words[i], FS, words[j], ORS, words[j], FS, words[i] | "sort --parallel=$(nproc) -S1G -us";
        }
    }
}

Fix the pair generation and also speed up the sorting


{
    if (1==NR)
    {
        startTimestamp = substr($1, 2, length($1) - 2)
        printf(";$FILEVERSION=1.3\n")
        printf(";$STARTTIME=%u.%u\n", mktime(strftime("%Y %m %d 0 0 0", startTimestamp)) / 86400 + 25569, \
                10000000000 / 86400 * (mktime(strftime("%Y %m %d %H %M %S", startTimestamp)) - mktime(strftime("%Y %m %d 0 0 0", startTimestamp))))
    }
    printf("%u) %.3f 1 Rx %s - %s", NR, (substr($1, 2, length($1) - 2) - startTimestamp) * 1000, $3, substr($4, 2, length($4) - 2))
    if (5<=NF)
    {
        for(i=5;i<=NF;i++)
        {
            printf " "$i
        }
    }
    printf "\n"
}

{
    if (1==NR)
    {
        startTimestamp = substr($1, 2, length($1) - 2)
        printf(";$FILEVERSION=1.3\n")
        printf(";$STARTTIME=%u.%u\n", mktime(strftime("%Y %m %d 0 0 0", startTimestamp)) / 86400 + 25569, \
                10000000000 / 86400 * (mktime(strftime("%Y %m %d %H %M %S", startTimestamp)) - mktime(strftime("%Y %m %d 0 0 0", startTimestamp))))
        currentTimeOffset = 0.0
    }
    else
    {
        previousTimeOffset = currentTimeOffset
        currentTimestamp = substr($1, 2, length($1) - 2)
        currentTimeOffset = currentTimestamp - startTimestamp
        if (currentTimeOffset < 0)
        {
            startTimestamp = currentTimestamp + currentTimeOffset
            currentTimeOffset = previousTimeOffset
        }
    }
    printf("%u) %.3f 1 Rx %s - %s", NR, currentTimeOffset * 1000, $3, substr($4, 2, length($4) - 2))
    if (5<=NF)
    {
        for(i=5;i<=NF;i++)
        {
            printf " "$i
        }
    }
    printf "\n"
}

Handle cases where system time is adjusted backwards (e.g. by NTP).


#!/usr/bin/awk
#
# Patch the generated wrapper Swift code to handle special cases
#
BEGIN { etpInit = 0 }
/public convenience init.T: ErrorTypeProtocol./ {
	etpInit = 1
	print "    /// Convenience copy constructor, creating a unique copy"
	print "    /// of the passed in Error.  Needs to be freed using free()"
	print "    /// (automatically done in deinit if you use ErrorType)."
}
/self.init.other.ptr./ {
	if (etpInit) {
		print "	self.init(g_error_copy(other.ptr))"
		etpInit = 0
		next
	}
}
/no reference counting for GError, cannot ref/ { next }
/no reference counting for GError, cannot unref/ {
	print "	    g_error_free(error_ptr)"
	next
}
/ -> GIConv {/, /^}/ {
	sub(/GIConv {/,"GIConv? {")
	sub(/return rv/,"return rv == unsafeBitCast(-1, to: GIConv.self) ? nil : rv")
}
// { print }

#!/usr/bin/awk
#
# Patch the generated wrapper Swift code to handle special cases
#
BEGIN { etpInit = 0 ; vaptrptr = 0 }
/public convenience init.T: ErrorTypeProtocol./ {
	etpInit = 1
	print "    /// Convenience copy constructor, creating a unique copy"
	print "    /// of the passed in Error.  Needs to be freed using free()"
	print "    /// (automatically done in deinit if you use ErrorType)."
}
/self.init.other.ptr./ {
	if (etpInit) {
		print "	self.init(g_error_copy(other.ptr))"
		etpInit = 0
		next
	}
}
/no reference counting for GError, cannot ref/ { next }
/no reference counting for GError, cannot unref/ {
	print "	    g_error_free(error_ptr)"
	next
}
/ -> GIConv {/, /^}/ {
	sub(/GIConv {/,"GIConv? {")
	sub(/return rv/,"return rv == unsafeBitCast(-1, to: GIConv.self) ? nil : rv")
}
/UnsafeMutablePointer.CVaListPointer/ {
	vaptrptr = 1
	print "#if !os(Linux)"
}
/^$/ {
	if (vaptrptr) {
		print "#endif"
		vaptrptr = 0
	}
}
/\/\/\// {
	if (vaptrptr) {
		print "#endif"
		vaptrptr = 0
	}
}
// { print }

Mark CVaListPointer array generators as unavailable on Linux


# $Id: ndcedit.awk,v 1.4 1997/02/22 16:08:19 peter Exp $
NR == 3 {
	print "#"
	print "# This file is generated automatically, do not edit it here!"
	print "# Please change src/usr.sbin/ndc/ndcedit.awk instead"
	print "#"
	print ""

	print "# If there is a global system configuration file, suck it in."
	print "if [ -f /etc/rc.conf ]; then"
	print "\t. /etc/rc.conf"
	print "fi\n"
}
{
	if ($1 == "named") {
		printf "\t\t# $namedflags is imported from /etc/rc.conf\n"
		printf "\t\tif [ \"X${named_flags}\" != X\"NO\" ]; then\n"
		printf "\t\t\tnamed ${named_flags} && {\n"
		getline
		printf "\t%s\n", $0
		getline
		printf "\t%s\n", $0
		getline
		printf "\t%s\n", $0
		printf "\t\tfi\n"
	} else {
	        if (/PATH=/) {
			gsub(":/usr/ucb:", ":", $0);
		      	if (!/export/) {
				$0=$0"\nexport PATH";
			}
		}
		print;
	}
}

# $Id: ndcedit.awk,v 1.5 1997/05/27 07:19:57 jkh Exp $
NR == 3 {
	print "#"
	print "# This file is generated automatically, do not edit it here!"
	print "# Please change src/usr.sbin/ndc/ndcedit.awk instead"
	print "#"
	print ""

	print "# If there is a global system configuration file, suck it in."
	print "if [ -f /etc/rc.conf ]; then"
	print "\t. /etc/rc.conf"
	print "fi\n"
}
{
	if ($1 == "named") {
		printf "\t\t# $named_flags is imported from /etc/rc.conf\n"
		printf "\t\tif [ \"X${named_enable}\" = X\"YES\" ]; then\n"
		printf "\t\t\tnamed ${named_flags} && {\n"
		getline
		printf "\t%s\n", $0
		getline
		printf "\t%s\n", $0
		getline
		printf "\t%s\n", $0
		printf "\t\tfi\n"
	} else {
	        if (/PATH=/) {
			gsub(":/usr/ucb:", ":", $0);
		      	if (!/export/) {
				$0=$0"\nexport PATH";
			}
		}
		print;
	}
}

Check named_enable rather than just named_flags. PR: 3893 (sort of)


BEGIN {
    FS = "\""
}

/\/us\/movie\// {
    numMovies += 1
    shortURL = $6
    printf ("%s    \"https://www.britbox.com%s\"", trailingComma, shortURL) >> EPISODES_JSON_FILE
    trailingComma = ",\n"
}

/\/us\/show\// {
    numShows += 1
    shortURL = $6
    printf ("%s    \"https://www.britbox.com%s\"", trailingComma, shortURL) >> EPISODES_JSON_FILE
    printf ("%s    \"https://www.britbox.com%s\"", trailingComma, shortURL) >> SEASONS_JSON_FILE
    trailingComma = ",\n"
}

END {
    print "" >> EPISODES_JSON_FILE
    print "" >> SEASONS_JSON_FILE
    print "==> Found " numMovies " movies"
    print "==> Found " numShows " shows"
}

BEGIN {
    FS = "\""
}

/\/us\/movie\// {
    numMovies += 1
    shortURL = $6
    printf ("%s    \"https://www.britbox.com%s\"", trailingEpisodesComma, shortURL) \
        >> EPISODES_JSON_FILE
    trailingEpisodesComma = ",\n"
}

/\/us\/show\// {
    numShows += 1
    shortURL = $6
    printf ("%s    \"https://www.britbox.com%s\"", trailingEpisodesComma, shortURL) \
        >> EPISODES_JSON_FILE
    trailingEpisodesComma = ",\n"
    printf ("%s    \"https://www.britbox.com%s\"", trailingSeasonsComma, shortURL) \
        >> SEASONS_JSON_FILE
    trailingSeasonsComma = ",\n"
}

END {
    print "" >> EPISODES_JSON_FILE
    print "" >> SEASONS_JSON_FILE
    print "==> Found " numMovies " movies"
    print "==> Found " numShows " shows"
}

Fix extra comma in json file

Fix extra comma in json file


# Usage: awk -f <this_script> vendor/MKxxxx.h vendor/MKxxyy.h vendor/MKzzz.h ...
/Processor[s]?:/ {
    i=0;
    if (FNR == NR) {
        printf "#if";
    } else {
        printf "#elif";
    }
    while(match($0, /MK.*/)) {
        if (i>0) {
            printf " || \\\n   ";
        }
        printf " defined(CPU_MODEL_%s)", substr($0, RSTART, RLENGTH);
        getline;
        i++;
    }
    printf("\n#include \"%s\"\n", FILENAME);
    nextfile;
}
END {
  print "#endif"
}

kinetis: Add script for generating vendor header include lines


#!/usr/bin/awk -f
# cat *.tdb | tdbout -t publisher,plugin,publisher:info[tester],status

BEGIN {
  FS="\t"
  pn = 0
}

{
    nn = split($2,na,/\./)
    lp2 = na[nn]
    if (!(($1,lp2) in b)) {
      p[pn] = $1
      n[pn] = lp2
  #    n[pn] = $2
      r[pn] = $3
      pn++
    }
    b[$1,lp2]++
    c[$1,lp2,$4]++
    x[$4]++
    tt++
}

END {
  s[0] = "expected"
  s[1] = "exists"
  s[2] = "manifest"
  s[3] = "wanted"
  s[4] = "crawling"
  s[5] = "testing"
  s[6] = "notReady"
  s[7] = "released"
  s[8] = "down"
  s[9] = "superseded"
  s[10] = "zapped"
  sn = 11

  sc[0] = "expe"
  sc[1] = "exis"
  sc[2] = "mani"
  sc[3] = "want"
  sc[4] = "craw"
  sc[5] = "test"
  sc[6] = "notR"
  sc[7] = "rele"
  sc[8] = "down"
  sc[9] = "supe"
  sc[10] = "zapp"
  scn = 11

  #print out header
  printf "Publisher\tPlugin\tT\tTotal"
  for (j = 0 ; j < scn ; j++) {
    if (x[s[j]] > 0) {
    printf "\t%s", sc[j]
    }
  }
  printf "\n"

  #print out publisher, plugin, tester, total aus
  for (i = 0 ; i < pn ; i++) {
    printf "%s\t%s\t%s\t%d", p[i], n[i], r[i], b[p[i],n[i]]
    for (j = 0 ; j < sn ; j++) {
      if (x[s[j]] > 0){
      if (c[p[i],n[i],s[j]] == 0) {
      printf "\t.."
    } else {
        printf "\t%d", c[p[i],n[i],s[j]]
      }
    }
    }
    printf "\n"
  }
    #print out bottom line sums
    printf "Publisher\tPlugin\tT\t%d", tt
    for (j = 0 ; j < sn ; j++) {
      if (x[s[j]] > 0) {
        printf "\t%d", x[s[j]]
      }
    }

  printf "\n"
}

Add new script for gln testing report

Add new script for gln testing report

git-svn-id: 293778eaa97c8c94097d610b1bd5133a8f478f36@24405 4f837ed2-42f5-46e7-a7a5-fa17313484d4


#!/usr/bin/env awk -f
#
# Generates a frequency table.
#
# Usage: frequency_table
#
# Input:
#   - a column of numbers
#
# Output:
#   - frequency table

{
	total += 1
	table[$1] += 1
}
END {
	for (v in table) {
		count = table[v]
		print v OFS count OFS count/total
	}
}

Add AWK script to generate a frequency table from a column of numbers


Add Tobias Waldekranz's awesome little AWK script

Signed-off-by: Joachim Nilsson <583c295fd7602c168ad814279bbc3894ba65f5d6@gmail.com>


BEGIN{ FS="\t"; OFS="\t"; }
{
 	possible_labels=$1;
 	rowid=$2;
    label=$3;
    features=$4;

 	label_count = split(possible_labels, label_array, ",");

	for(i = 1; i <= label_count; i++) {
    	if (label_array[i] == label)
      		print rowid, label, 1, features;
      	else
      		print rowid, label_array[i], -1, features;
	}
}
END{}

Add an awk script used in one-vs-the-rest classification example.


#!/usr/bin/env awk -f

{
    for (i = 1; i <= NF; i++) {
        if (i == 3) printf "-1 ";
        printf $i" "
    }
    printf "\n"
}

Add script to convert old submission format to new format.


# WebScraper has problems getting incomplete data.
#
# Crosscheck the info in EPISODES with the info in SEASONS. Count up episodes
# and compare with the number of episodes listed in the seasons file.

# For now these seem more likely a problem in scraping SEASONS than EPISODES
# so it could be these are false positives in generating spreadsheets.
# Problems listed in BBox_anomalies files are more likely to be real.

# INVOCATION
#    awk -f verifyBBoxInfoFrom-webscraper.awk BBox_episodeInfo-180421.123042.txt

/ movie / {
    title = $3
    numEpisodes = $5
    if (numEpisodes == 0)
        print
}

/ show / {
    numShows += 1
    showTitle[numShows] = $3
    shouldHave[numShows] = $5
    doesHave[numShows] = 0
    if (numEpisodes == 0)
        print
}

/^         / {
    epis  = NF-1
    if ($epis !~ /^[[:digit:]]*$/)
        print "==> Bad input line " NR "\n" $0
    else
        doesHave[numShows] += $epis
}

END {
    print ""
    for ( i = 1; i <= numShows; i++ ) {
        if (shouldHave[i] != doesHave[i]) {
            print "==> show  "showTitle[i] " has " doesHave[i] " instead of " \
                shouldHave[i] " episodes."
        }
    }
}

Add crosscheck of EPISODES with SEASONS

Add crosscheck of EPISODES with SEASONS


Add parser for Z3's get-model output.

Add parser for Z3's get-model output.

Doesn't really parse it, it just reformats it into something less
rubbish.


#!/usr/bin/awk -f

{
    protein = ""
    flag = 0    # Get rid of line with label
    while (("curl -Ls http://www.uniprot.org/uniprot/"$1".fasta" | getline prot_line) > 0) {
        if (flag)
            # Append line to protein
            protein = protein prot_line
        else
            # We're on the first line - ignore label and set flag
            flag = 1
    }

    first = 1    # Print label only once
    startidx = 1
    do {
        where = match(substr(protein, startidx), /N[^P][ST][^P]/)
        if (where != 0) {
            if (first) {
                # Print label, start location string
                print $0
                loc_string = where + startidx - 1
                # Reset flag
                first = 0
            }
            else {
                # Append to location string
                loc_string = loc_string " " where + startidx - 1
            }
            # Update offset: start one after start of last match
            startidx += where
        }
    } while (where != 0)

    # Did we find something?
    if (loc_string)
        print loc_string
}

Add awk solution to problem 16

Add awk solution to problem 16


# Crosscheck the number of episodes of each show found by counting them (grep -c)
# in EPISODES_SORTED_FILE versus the number added up from SEASONS_SORTED_FILE
# Both numbers are found by processing a checkEpisodeInfo file
#
# For now these seem more likely a problem in scraping SEASONS_SORTED_FILE than EPISODES_SORTED_FILE
# so it could be these are false positives in generating spreadsheets. The case is stronger for
# problems listed in checkBBox_anomalies files.

# INVOCATION:
#    awk -f crosscheckInfo.awk checkEpisodeInfo-180415.185805.txt

/ movie / {
    title = $3
    numEpisodes = $5
    if (numEpisodes == 0)
        print
}

/ show / {
    numShows += 1
    showTitle[numShows] = $3
    shouldHave[numShows] = $5
    doesHave[numShows] = 0
    if (numEpisodes == 0)
        print
}

/^         / {
    epis  = NF-1
    if ($epis !~ /^[[:digit:]]*$/)
        print "==> Bad input line " NR "\n" $0
    else
        doesHave[numShows] += $epis
}

END {
    for ( i = 1; i <= numShows; i++ ) {
        if (shouldHave[i] != doesHave[i]) {
            print "==> show  "showTitle[i] " has " doesHave[i] " instead of " \
                shouldHave[i] " episodes."
        }
    }
}

Add a crosscheck for the SEASONS_SORTED_FILE


#!/usr/bin/awk -f
#
# AWK script to join multiple lines if the preceeding line ends with a comma (,).
#
# For example:
#
#   1,
#   2,
#   3
#
# Turns into:
#
#   1, 2, 3
#

/,$/ {
    ORS=""
    print $0
    do {
        getline
        print $0
    } while ($0 ~ /,$/)
    ORS="\n"
    print ""
}

Add AWK script to merge comma-terminated lines


# Helper for converting Netflix "viewing activity" into hyperlinks
#

# Death in Paradise: Season 6: "Man Overboard, Part 2"
# Ugly Delicious: Season 1: "Pizza"
# Hinterland: Season 3: "Episode 2"

# INVOCATION:
#    Browse to https://www.netflix.com/viewingactivity
#    Save as 'Page Source'
#    awk -f generateLinksFrom-NetflixActivityPage.awk ~/Downloads/Netflix.html

BEGIN {
    RS="\<"
    # print 10 records unless overridden with "-v maxRecordsToPrint=<n>"
    if (maxRecordsToPrint == "") maxRecordsToPrint = 10
}

/div class="col date nowrap"/ {
    split ($0,fld,">")
    date = fld[2]
}

/a href="\/title\// {
    split ($0,fld,">")
    title = fld[2]
    split ($0,fld,"\"")
    URL = fld[2]
    gsub (/"/,"",title)
    printf ("=HYPERLINK(\"https://www.netflix.com/%s\";\"%s\")\t%s\tNetflix Streaming\n",\
        URL,title,date)
    recordsPrinted += 1
    if (recordsPrinted >= maxRecordsToPrint)
        exit
}

Add Netflix specific link generator

Add Netflix specific link generator


#!/usr/bin/env awk -f
#
# Computes the corrected sample standard deviation.
#
# Usage: stdev
#
# Input:
#   - a column of numbers
#
# Output:
#   - corrected sample standard deviation
#
# Notes:
#   - Uses [Welford's method][1].
#
# [1]: https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online_algorithm

BEGIN {
	delta = 0
	mean = 0
	M2 = 0
	N = 0
}
{
	N += 1
	delta = $1 - mean
	mean += delta / N
	M2 += delta * ($1 - mu)
}
END {
	if (N < 2) {
		print 0
	} else {
		print sqrt(M2 / (N-1))
	}
}

Add AWK script to compute the corrected sample standard deviation


BEGIN {
    FS="\t"
    print "Sortkey\tTitle\tSeasons\tDuration\tYear\tRating\tDescription"
}

# if needed for debugging record placment, replace "/nosuchrecord/" below
/nosuchrecord/ {
    print ""
    print NR " - " $0
    for ( i = 1; i <= NF; i++ ) {
        print "field " i " = " $i
    }
}

{
    for ( i = 1; i <= NF; i++ ) {
        if ($i == "null")
            $i = ""
    }
}

/\/us\/movie\/|\/us\/show\//{
    URL = $3
    showTitle = $4
    Year = $5
    NumSeasons = $6
    Duration = $7
    Rating = $8
    Description = $9

    sub (/ Season[s]/,"",NumSeasons)
    sub( / min/,"",Duration)

    # Convert duration from minutes to HMS
    secs = 0
    mins = Duration % 60
    hrs = int(Duration / 60)
    HMS = sprintf ("%02d:%02d:%02d", hrs, mins, secs)

    # Titles starting with "The" should not sort based on "The"
    if (match (showTitle, /^The /)) {
        showTitle = substr(showTitle, 5) ", The"
    }
}

/\/us\/movie\// {
    # Extract movie sortkey from URL
    nflds = split (URL,fld,"_")
    if (URL ~ /_[[:digit:]]*$/) {
        sortkey = sprintf ("M%05d", fld[nflds])
        printf \
            ("%s %s - mv\t=HYPERLINK(\"https://www.britbox.com%s\";\"%s, %s, %s\"\)\t\t%s\t%s\t%s\t%s\n", \
             showTitle, sortkey, URL, showTitle, sortkey, \
             Title, HMS, Year, Rating, Description)
    }
    next
}

/\/us\/show\// {
    # Extract show sortkey from URL
    nflds = split (URL,fld,"_")
    if (URL ~ /_[[:digit:]]*$/) {
        sortkey = sprintf ("S%05d", fld[nflds])
        printf \
            ("%s %s - sh\t=HYPERLINK(\"https://www.britbox.com%s\";\"%s, %s, %s\"\)\t\t%s\t%s\t%s\t%s\n", \
             showTitle, sortkey, URL, showTitle, sortkey, \
             Title, HMS, Year, Rating, Description)
    }
    next
}

Make script to process top level BritBox shows


# Helper for converting Netflix "viewing activity" into hyperlinks
#
# Since there is no way to paste an embedded hyperlink into a text filei,
# paste the link and the title on two consecutive lines, e.g.
#
# https://www.netflix.com/title/80174814
# Borderliner: Season 1: "Milla’s Future"
# https://www.netflix.com/title/80203122
# Luxury Travel Show: Season 1: "Chiang Mai & Eze"
# https://www.netflix.com/title/80217826
# Kavin Jay: Everybody Calm Down!

/^https:/ {
    link = $0
    if ((getline title) > 0) {
        gsub (/"/,"\"\"",title)
        printf ("=HYPERLINK(\"%s\";\"%s\")\n",link,title)
    }
}

Create helper for Netflix activity

Create helper for Netflix activity


# Print field numbers and field names from a WebScraper csv file saved in tsv format

# INVOCATION:
#   awk -f printFieldNamesFrom-webscraper.awk -v maxRecordsToPrint=5 BritBoxSeasons-test-tabs.csv

BEGIN {
    FS="\t"
    # print 3 records unless overridden with "-v maxRecordsToPrint=<n>"
    if (maxRecordsToPrint == "") maxRecordsToPrint = 3
}

NR <= maxRecordsToPrint {
    print "Record " NR
    for ( i = 1; i <= NF; i++ ) {
        print i " - " $i
    }
    print ""
}

Add debugging tool which prints WebScraper field names


#!/usr/bin/awk -f
BEGIN{
    FS = OFS = "\t";
}
{
    split($3, words, ", ");
    for (i = 1; i <= length(words) - 1; i++) {
        for (j = i + 1; j <= length(words); j++) {
            print words[i], words[j];
            print words[j], words[i];
        }
    }
}

Add the unified pair generation script

Add the unified pair generation script


BEGIN {
  OFS="\t";
  lastid="";
  id_counts=0;
}
{
  if ( $1 ~ /^@/ )
  {
    # headers go straight through
    print $0;
    next;
  }
  if (lastid == "") {
    lastid=$1;
    r1["read"] = $0;
    r1["chr"] = $3;
    r1["tags"] = "";
    for(i=12;i<NF;i++) { r1["tags"]=r1["tags"] $i " ";}
    r1["tags"]=r1["tags"] $i;
    next;
  }

  if ( lastid == $1 ) {
    id_counts++;
    if ( id_counts == 2 ) {
      r2["read"] = $0;
      r2["chr"] = $3;
      r2["tags"] = "";
      for(i=12;i<NF;i++) { r2["tags"]=r2["tags"] $i " ";}
      r2["tags"]=r2["tags"] $i;
    }
  } else if ( lastid != $1 ) {
    if ( 2 == id_counts ) {
      # two matching ends of a pair, should we include them?
      if ( (r1["chr"] ~ /chr([[:digit:]]+|[XY]|MT)/) && (r2["chr"] ~ /chr([[:digit:]]+|[XY]|MT)/) &&
           (r1["tags"] ~ /XT:A:U/) && (r2["tags"] ~ /XT:A:U/) ) {
             print r1["read"];
             print r2["read"];
      }
    }
    id_counts=1;
    lastid=$1;
    r1["read"] = $0;
    r1["chr"] = $3;
    r1["tags"]="";
    for(i=12;i<NF;i++) { r1["tags"]=r1["tags"] $i " ";}
    r1["tags"]=r1["tags"] $i;
  }

}
END {
  if ( 2 == id_counts ) {
    # two matching ends of a pair, should we include them?
    if ( (r1["chr"] ~ /chr([[:digit:]]+|[XY]|MT)/) && (r2["chr"] ~ /chr([[:digit:]]+|[XY]|MT)/) &&
         (r1["tags"] ~ /XT:A:U/) && (r2["tags"] ~ /XT:A:U/) ) {
           print r1["read"];
           print r2["read"];
    }
  }
}

Add only unique reads for paired end filter


# Usage:
# awk -f deobfuscate_wasm_log.awk <wat_file> <log_file>

# Process the log file which is the 2nd argument.
FILENAME == ARGV[2] {
  match($0, /<anonymous>:wasm-function\[([0-9]+)\]/, groups)
  print $0, functions[groups[1]]
}

# Collects function declarations
/^\(func/ {
  functions[last_function++] =  $2
}

[WASM] Add awk script to deobfuscate wasm stack traces.

PiperOrigin-RevId: 363962157


#!/usr/bin/env awk -f
#
# Computes the mid-range.
#
# Usage: mid-range
#
# Input:
#   - a column of numbers
#
# Output:
#   - mid-range

!i++ {
	# Only for the first record:
	max = $1
	min = $1
}
{
	if ($1 > max) {
		max = $1
	} else if ($1 < min) {
		min = $1
	}
}
END {
	print (max + min) / 2
}

Add AWK script to compute the mid-range

Add AWK script to compute the mid-range


BEGIN{
        now = systime()
        format = "%Y/%m/%d %H:%M:%S"

}
{
        split($1, DATE, "/")
        split($2, TIME, ":")
        $1 = ""
        $2 = ""
        t = mktime(DATE[1] " " DATE[2] " " DATE[3] " " TIME[1] " " TIME[2] " " TIME[3])
        if (delta == "") {
                delta = now - t
        }
        print strftime(format, t + delta) $0
}

Add a short program that rewrites the testdata/rsyncd.log timestamps to nowish.


#!/usr/bin/awk -f

BEGIN{
	outarr[0] = "";
	outarr[1] = "";
	outarr[2] = "";
	outarr[3] = "";
	idx = 0;
}

/.*sparticus.*/{
	sub(/bv/, "", $12);
	outarr[idx] = $12;
	idx++;
	if (idx == 4) {
		print outarr[0] "|" outarr[1] "|" outarr[2] "|" outarr[3]
		idx = 0;
	}
}

Add an awk script for reading CVC's output.

Fragile. But never mind.


# Invoke as awk addloadexample.awk

BEGIN {
  lms = 0;
}

tolower($0) ~ /^[# \t]*loadmodule[ \t]/ {
  if ( $2 == MODULE "_module" ) {
    print "LoadModule " MODULE "_module " LIBPATH "/mod_" MODULE DSO;
    lms = 2;
    next;
  }
  # test $3 since # LoadModule is split into two tokens
  else if ( $3 == MODULE "_module" ) {
    print $1 "LoadModule " MODULE "_module " LIBPATH "/mod_" MODULE DSO;
    lms = 2;
    next;
  }
  else if ( ! lms ) lms = 1;
}

$0 ~ /^[ \t]*$/ && lms == 1 {
  print "LoadModule " MODULE "_module " LIBPATH "/mod_" MODULE DSO;
  lms = 2;
}

tolower($0) ~ /^[# \t]*include[ \t]/ && $NF == EXAMPLECONF {
  lms = 3;
}

{ print }

END {
  if ( lms < 3 ) {
    if ( ! /^[ \t]*$/ ) print "";
    if ( lms < 2 ) {
      print "LoadModule " MODULE "_module " LIBPATH "/mod_" MODULE DSO;
      print "";
    }
    if ( length(EXAMPLECONF) ) {
      print "# Example mod_" MODULE " configuration";
      print "#Include " EXAMPLECONF "\n";
    }
  }
}

Add for updating the config file

Add for updating the config file

git-svn-id: 244fd0a71b5b35931765a3ae1f99e3319f3fb8ab@822470 13f79535-47bb-0310-9956-ffa450edef68