Posix utilities

Top  Previous  Next

The GAMS system for Windows includes a collection of Posix utilities generally for file manipulation.  These utilities are typically available on Unix systems and therefore allow one to write platform independent file manipulation scripts, do file manipulations, compare files and do other things. The following utilities are available:

AWK

A general purpose programming language that is designed for processing text-based data, either in files or data streams, and was created at Bell Labs in the 1970s.  AWK is described here.

CAT

A command to concatenate and display files. CAT is described here.

CKSUM

Reads files and calculates a checksum, cyclic redundancy check and the byte count for each. CKSUM is described here

CMP

Compares two files of any type and writes the results to standard output. CMP results are empty if the files are the same; if they differ, the byte and line number at which the first difference occurred is reported. CMP is described here

COMM

Reads two files as input, then outputs one file with three columns. The first two columns contain lines unique to the first and second file, respectively. The last column contains lines common to both. COMM is described here

CP

A utility that copies a file to a destination. CP is described here

CUT

A utility which extract sections from lines of  a file.  Extraction of line segments can typically be done by bytes, characters, or fields. CUT is described here.

DIFF

A file comparison utility that outputs the differences between two files, or the changes made to a current file by comparing it to a former version of the same file. Diff displays the changes made per line for text files. DIFF is described here

EXPR

Evaluates a numerical expression and outputs the corresponding value. EXPR is described here

FOLD

Utility for breaking long lines into lines that have a maximum width. FOLD is described here.

GDATE

Tells the current date and time and is a variant of the UNIX command DATE which is described here.

GREP

Finds text within a file.  GREP is described here.

GSORT

Sorts the lines in a text file. Renamed from the UNIX command SORT which is described here.

HEAD

Prints the first 10 lines of a file to the GAMS LOG file. The number of lines printed may be changed with a command line option. HEAD is described here.

JOIN

Merges the lines of two sorted text files based on the presence of a common field. JOIN is described here

MV

Moves files or directories from one place to another. When this is used the original file is deleted, and the new file may have the same or a different name. When the original and new files are in the same directory MV will rename the file instead.   MOVE is described here

OD

Create an octal, hexadecimal or decimal dump of the data in a file. HEAD is described here

PASTE

Merges the lines of two files placing the contents of each line of a file at the end of the corresponding line of another file.  PASTE is described here

PRINTF

Takes an input string and writes it in a formatted fashion according to a formatting string.  Bolded line, font color, numeric  formats and other things can be specified.  PRINTF is described here

RM

Deletes files or directories.  RM is described here

SED

A batch executed file editor that follows prespecified commands to make changes to a text file. SED is described here

SLEEP

A command that causes execution to pause for a specified amount of time.  SLEEP is described here

TAIL

Prints the last 10 lines of a file to the GAMS LOG file. The number of lines printed may be changed with a command line option. TAIL is described here.

TEE

Reads information from an input source and copies to the LOG file.  Can be used to list all files that match a particular mask.  TEE is described here.

TEST

A command that tests to see if an expression is true.  TEST is described here.

TR

Translate characters in a file to other characters using a user specified translation scheme generating a translated output file.  TR is described here and here

UNIQ

Reports on the incidence of  or removes any adjacent duplicate lines in a file. UNIQ is described here.

WC

Counts words, lines, and or bytes in a file . WC is described here.

XARGS

Build and execute commands based on a file. XARGS is described here.

 

The collection consists of Windows versions of the GNU implementation of these utilities from Sourceforge. Detailed descriptions of the utilities can be found at the GNU website.  The utilities “gdate” and “gsort” a renamed relative to the LINUX/UNIX commands of “date” and “sort” to avoid conflicts with the Windows commands “date” and “sort”. For compatibility reasons the GNU implementation of awk called “gawk” has been renamed to “awk”.

The diff utility can be used to compare files as in the example below or in the file filecompare.gms

*identify name of first file to compare

$setglobal file1 "tranerr.gms"

*identify name of second file to compare

$setglobal file2 "tranport.gms"

*show the control variables so you can check names are rifht

$show

*invoke the difference

$call "diff.exe %file1% %file2%"

*note the differences are shown in the LOG file

 

Examples can be found in the section  GAMS Model Library under the files classified with application area GAMS Tools.  The awk utility can be used to transform a variety of different text inputs into GAMS readable input files as illustrated in the model library file awkqap.gms.