login about faq

Sometimes when transferring files from z/os to unix in a line mode ascii transfer that will strip trailing spaces, how do you pad the files?

asked Dec 27 '10 at 16:56

SSH%20KB's gravatar image

SSH KB ♦
509249246237


Shown below is a utility for Unix systems to add trailing blanks into files afterwards. It is possible for example to execute this utility using remote command (ssh2 user@server "ssh-pad-file infile.txt outfile.pad") to add trailing blanks on transferred files.

The utility changes padding of the file. Each line is either truncated to given record length or the line is padded with spaces to the given record length. Newline characters can be added to the end of each record. If 'infile' and 'outfile' are missing, data is read from stdin and written to stdout.

Usage:

./ssh-pad-file [options] [infile outfile]

Options:

-l|--lrecl n Record length of the file (default is 80).

-f|--format s Transfer format of the file. Transfer format can be either stream or line. If file has been transferred using stream format, padding is preserved in the file. Line format removes padding and the padding must be added (default is line).

-n|--newline s Newline character to be added to the end of each record (default is '\n'). Use empty string '' to prevent newline characters to be added.

-?|-h|--help Show this text.

For example:

ssh-pad-file infile.txt outfile.pad

#!/bin/sh
#
# ssh-pad-file
#
# Author: Tommi Linnakangas
#
# Copyright (c) 2007 SSH Communications Security, Finland
#               All rights reserved.
#

#
# Defaults.
#
lrecl=80
format=line
newline="\n"
in="-"
out="-"
#tmp==${TMPDIR-/tmp}/`basename $0`.$$

#
# Prefer xpg4 binaries on Solaris
#
PATH=/usr/xpg4/bin:$PATH

usage()
{
  exec 1>&2
cat "$out"
fi
if [ "X$in" != "X-" ]; then
  exec /dev/null
else
  #
  # Padding is not needed.
  #
  cat
fi | \
if [ "$newline" ]; then
  fold -b -w $lrecl | awk '{printf("%s%s", $0, "'$newline'")}'
else
  cat
fi
link

answered Dec 27 '10 at 21:03

renaes's gravatar image

renaes ♦
2462

edited Mar 15 '11 at 06:57

SSH%20KB's gravatar image

SSH KB ♦
509249246237

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×63
×34
×10
×1

Asked: Dec 27 '10 at 16:56

Seen: 5,904 times

Last updated: Mar 15 '11 at 06:57

All user contributed content licensed under the cc-by-sa license.
Powered by OSQA.