: ########################################################################## # Shellscript: dequote - undo "quoting" of a text # Versionsnr : 0.1 (beta) # Author : Heiner Steven (heiner.steven@odn.de) # Date : 11/01/94 # Category : Mail, Text Utilities # SCCS-Id. : $Id: dequote,v 1.1.1.1 1999/06/15 19:29:05 heiner Exp $ ########################################################################## # Description # Removes any leading " >" from stdin, and writes to stderr. # The first quote string (i.e. " >") is written to stdout. # # Example: # The following two lines # | > this is a quoted text # | > and this too # become # | this is a quoted text # | and this too # (The vertical bar denotes the left margin). # On stdout appears the following output: # | > ########################################################################## PN=`basename $0` # program name VER='0.1 (beta)' Usage () { echo "$PN - short description, $VER (stv '94)" exit 1 } Msg () { for i do echo "$PN: $i" >&2 done } Fatal () { Msg "$@"; exit 1; } # swap stdout and stderr exec 3>&1 1>&2 2>&3 3>&- nawk ' $1 ~ />/ { while ( $0 ~ /^[ ]*>/ ) { if ( QStr == "" && match ($0, "^[ ]*>") ) Q = Q substr ($0, RSTART, RLENGTH) sub ("^[ ]*>", "") # remove all quotes } if ( QStr == "" ) QStr = Q } {print} END { if ( QStr != "" ) print QStr | "exec >&2; cat" } ' "$@"