SACHIN  SHANBHAG
 

Research
  Links | Resources


Resources: Miscellaneous


  • Histogram: histogram.awk
    Produces a histogram. Input file -data.in- contains a single column of values. To bin data with data values between -xmin- and -xmax-, with -nbin- bins. Usage: gawk -f histogram.awk xmin xmax nbin data.out data.in.

  • Linear Regression: linreg.awk
    Given data.in containing two columns x and y, outputs a=slope and b=intercept. Usage: awk -f linreg.awk data.in.

  • Extract internal segment: chop.sh
    chop.sh 5 7 data.in, outputs lines 5-7 (3 lines) of the file data.in

  • Statistics: statistics.awk
    awk -f stat.awk data.n, outputs the arithmetic mean, standard deviation and standard error of column 2.

  • Append columns from a different file: appendcol.sh
    To append column "n" from file2 to file1, appendcol.sh file1 file2 n

  • Add two tables: AddTables.sh
    Given two identically structured files (# columns, and lines) adds up respective elements. Right now assumes all rows have the same number of columns. Usage: sh AddColFiles.sh f1 f2 ncol

  • Big-small endian conversion:
    DOS to Unix: awk '{sub(/\r$/,"");print}'
    Unix to DOS: awk '{sub(/$/,"\r");print}'

  • Substitution and Find:
    (From Eric Pemente: http://www.student.northpark.edu/pemente/awk/awk1line.txt)
    # substitute "foo" with "bar" ONLY for lines which contain "baz"
    awk '/baz/{gsub(/foo/, "bar")};{print}'
    # substitute "foo" with "bar" EXCEPT for lines which contain "baz"
    awk '!/baz/{gsub(/foo/, "bar")};{print}'
    # change "scarlet" or "ruby" or "puce" to "red"
    awk '{gsub(/scarlet|ruby|puce/, "red"); print}'
    # print section of file between two regular expressions (inclusive)
    awk '/Iowa/,/Montana/' # case sensitive

  • Join PDFs using Ghostscript: joinpdf.sh
    Joins two or more files into a single PDF file called JoinedFiles.pdf
    Usage: sh joinpdf.sh f1.pdf f2.pdf f3.pdf
    Globbing is allowed: sh joinpdf.sh f*.pdf

  • Text to LaTeX columns: txt2textable.awk
    Given text file with arbitrary number of columns, outputs in latex format.













© 2008 Sachin Shanbhag
Last Modified: 10/21/2008