: ########################################################################## # Shellscript: unquote - undo "quoting" of a text # Versionsnr : 1.2 # Author : Heiner Steven # Date : 1994-01-11 # Category : Text Utilities # SCCS-Id. : @(#) unquote 1.2 04/02/18 ########################################################################## # Description # Removes any leading " >" from stdin, and writes 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). ########################################################################## PN=`basename "$0"` # Program name VER='1.2' : ${NAWK:=nawk} Usage () { echo "$PN - remove \"quotes\" from a text, $VER (stv '94) usage: $PN [-a] [file ...] -a: remove all levels of quoting (default: only the first level)" exit 1 } Msg () { for MsgLine do echo "$PN: $MsgLine" >&2 done } Fatal () { Msg "$@"; exit 1; } set -- `getopt ah "$@"` || Usage [ $# -lt 1 ] && Usage # "getopt" detected an error AllLevels=false while [ $# -gt 0 ] do case "$1" in -a) AllLevels=true;; --) shift; break;; -h) Usage;; -*) Usage;; *) break;; # First file name esac shift done $NAWK ' $1 ~ />/ { if ( "'"$AllLevels"'" == "true" ) { while ( $0 ~ /^[ ]*>/ ) { if ( QStr == "" && match ($0, "^[ ]*>") ) Q = Q substr ($0, RSTART, RLENGTH) sub ("^[ ]*>[ ]*", "") # remove all quotes } if ( QStr == "" ) QStr = Q } else { if ( QStr == "" && match ($0, "^[ ]*>") ) QStr = substr ($0, RSTART, RLENGTH) sub ("^[ ]*>[ ]*", "") # remove all quotes } } {print} ' "$@"