#****************************************************************************
#  ##   ##         #####   #####  ##     **       NoSQL RDBMS - record      *
#  ###  ##        ####### ####### ##     **        $Revision: 2.1 $			*
#  #### ##        ###     ##   ## ##     ************************************
#  #######  ####  #####   ##   ## ##     **      Carlo Strozzi (c) 1998     *
#  ####### ######   ##### ## # ## ##     ************************************
#  ## #### ##  ##     ### ##  ### ##     **           Written by            *
#  ##  ### ###### ####### ######  ###### **          Carlo Strozzi          *
#  ##   ##  ####   #####   #### # ###### **     e-mail: carlos@linux.it     *
#****************************************************************************
#   NoSQL RDBMS, Copyright (C) 1998 Carlo Strozzi.                          *
#   This program comes with ABSOLUTELY NO WARRANTY; for details             *
#   refer to the GNU General Public License.                                *
#****************************************************************************
#
#  Print a specified record No. from a table.
#
#  Takes a record number and outputs the corresponding record of the 
#  input table. If two numbers are specified, then outputs the
#  corresponding range of records. If the second number is lesser
#  than the first, then all records starting from the first record
#  number to the end of table are printed. If no record or if an 
#  out-of-range record is specified, then only the table header is
#  printed.
#
#  This NoSQL operator reads a table on STDIN and writes a table to STDOUT.
#
########################################################################

########################################################################
# BEGIN block
########################################################################

BEGIN \
{
  NULL = ""; FS = OFS = "\t";
  if ( ! split( __nosql_args, range, " " ) ) range[1] = 0
  if ( range[2] == NULL ) range[2] = range[1]
}

########################################################################
# Main loop
########################################################################

NR < 3 { print; next }

range[1] == ( NR-2 ) { start_printing = 1 }

start_printing == 1 { print }

range[2] == ( NR-2 ) { start_printing = 0 }

