
#-----------------------------------------------------------------------
# Copyright (C) 2000-2001, Jean-Sebastien Morisset <jsmoriss@mvlan.net>
#-----------------------------------------------------------------------
# $Id: chop_and_swap.sh,v 1.4 2001/08/11 17:01:20 jsmoriss Exp $
#-----------------------------------------------------------------------
#  $RCSfile: chop_and_swap.sh,v $
#   $Author: jsmoriss $
# $Revision: 1.4 $
#     $Date: 2001/08/11 17:01:20 $
#   $Locker:  $ 
#     $Name:  $
#-----------------------------------------------------------------------
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by 
# the Free Software Foundation <http://www.gnu.org/copyleft/gpl.txt>.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License (LICENSE file in archive) for more details.
#
#-----------------------------------------------------------------------
# README
#-----------------------------------------------------------------------
#
# A bourne shell function used by rcf; a very secure, fast, and complete
# firewall for linux <http://jsmoriss.mvlan.net/linux/rcf.html>.
#
# Chop a string at a specified position and swap the pieces.
#
# Syntax: echo "string to swap"|Chop_And_Swap {pos}
#
# In the following example, we use Chop_And_Swap to replace sort's -k
# parameter (sort -k 1.4 filename.txt).
#
# Example: cat filename.txt|Chop_And_Swap 4|sort|Unchop_And_Swap 4
#
#-----------------------------------------------------------------------
# FUNCTION
#-----------------------------------------------------------------------

Chop_And_Swap () { sed -n -e "s/^\(.\{`expr $1 - 1`\}\)\(.*\)$/\2\1/p"; }

Unchop_And_Swap () { sed -n -e "s/^\(.*\)\(.\{`expr $1 - 1`\}\)$/\2\1/p"; }

