#!/bin/bash # Sun Feb 22 03:20:45 EST 2004 # NAME: moveline # Copyright 2004, Chris F.A. Johnson # Released under the terms of the GNU General Public License [ $# -lt 2 ] && { printf "\n \e[1m${0##*/}\e[0m: move a line in a file to a different line\n\n" fmt=" USAGE: %s %s %s %s \n\n" printf "$fmt" "${0##*/}" source destination "[file ...]" printf "\tMore than one file may be given\n" printf "\tIf none are given, stdin is used\n\n" printf "\tThe result is printed to stdout\n\n" exit } IFS=$'\n' sline=$(( $1 - 1 )) dline=$(( $2 - 1 )) shift 2 file=( `cat "$@"` ) mvline=${file[$sline]} unset file[$sline] file=( "${file[@]}" ) line=0 printf "%s\n" "${file[@]}" | head -$dline printf "%s\n" "$mvline" set -- "${file[@]}" shift $dline printf "%s\n" "$@"