Path: utzoo!attcan!uunet!allbery From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) Newsgroups: comp.sources.misc Subject: v08i014: line wrapper for BIT/EARNnet mailings Message-ID: <64927@uunet.UU.NET> Date: 25 Aug 89 01:47:44 GMT Sender: allbery@uunet.UU.NET Reply-To: wsinrobg@urc.tue.nl (Rob Gerth) Organization: Eindhoven University of Technology, The Netherlands Lines: 163 Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) Posting-number: Volume 8, Issue 14 Submitted-by: wsinrobg@urc.tue.nl (Rob Gerth) Archive-name: wrap IBM is still firmly committed to Holerith cards as BIT/EARNnet users can testify. Here is a shell script that wraps long lines in a file so that they can be reconstituted by piping thru sh---see the comments in the script. This script uses sed and has been tested on SUNs and ULTRIX vaxen. The ULTRIX sed is buggy, so I had to rewrite the wrap script. The original unwrap script worked on both systems. In other words: there may be surprises. Enjoy, # Rob Gerth # # # # uucp: wsinrobg@eutrc3.urc.tue.nl | Eindhoven University of Technology # # bitnet: wsdcrobg@heitue5 | 5600 MB Eindhoven, The Netherlands # #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'wrap' <<'END_OF_FILE' X: !/bin/sh X# NAME X# wrap X# SYNOPSIS X# wrap [-nnn] [-s] [file] X# DESCRIPTION X# Wrap wraps lines to nnn chars (default 80): BITNET does not like X# lines longer than that. X# It reads file (standard input if no file is specified) and X# writes lines of specified maximal length to standard output, X# embedded in a shell script running of which restores the original. X# If file is specified, wrap checks if it is a shar file (by searching X# for the string "# This is a shell archive" at the start of a line) X# and, if so, adapts the surrounding shell script appropriately. X# Specifying -s makes wrap behave as if it were wrapping a shar file X# without checking. X# Recommended use: shar foo ... | wrap -s >bar X# to be restored with sh bar X# VERSION X# 1.1 X# BUGS X# This should of course be an option of shar. X# AUTHOR X# Rob Gerth, Eindhoven University of Technology X# wsinrobg@eutrc3.urc.tue.nl or WSDCROBG@HEITUE5.BITNET X# X# XFILE= XSHAR= XDEFAULT=79 XLEN=$DEFAULT XLINE= XCL="+" XLL="-" X Xfor i Xdo X case $i in X -[0-9] | -[0-9][0-9] | -[0-9][0-9][0-9]) LEN=`expr $i : '-\(.*\)'`;; X -s) SHAR=1;; X -*) echo "Usage: wrap [-nnn] [-s] [file]" 1>&2; exit 1;; X *) FILE="$i"; break;; X esac Xdone X Xtest \( -z "$SHAR" \) -a \( -n "$FILE" \) && X SHAR=`egrep '^# This is a shell archive' $FILE` X Xif test $LEN -eq 0 Xthen echo "Linelength ($LEN) set to default: `expr $DEFAULT + 1`" 1>&2; X LEN=$DEFAULT Xfi X XLINE=`yes | sed " X H X $LEN { g X s/\\n//g X y/y/./ X q X } X d" 2>/dev/null` X Xcat <<\EOF X: !/bin/sh X# Remove everything before the previous line and pipe through sh. X# XEOF Xif test "$SHAR" Xthen echo "{ sed '" Xelse echo "sed '" Xfi Xcat <