OpenExtensions for z/VM "Q"s and "A"s

Question: Occasionally I run into trailing blanks in an BFS file, typically if I OPENVM PUT a file into the BFS from a fixed-record format file. How can I get rid of the trailing blanks?

Response: If you have trailing blanks in an BFS file, they will generally cause problems with continuation lines in C source files, makefiles, shell scripts, etc.

A simple cat does not show the trailing blanks. Use the -ve options to print a dollar sign at the end of each logical line. Then it becomes more obvious that there are trailing blanks. For example,

/u/donovan> cat -ve makefile
all:
$
 
        echo this is a \
       $
test
$

If you use XEDIT with hex characters set on, this also shows the trailing blanks.

There are several methods you can use to eliminate the trailing blanks. Any of the following should work:

  1. Using sed:
    sed 's/ *$//' < in_file > out_file
    
    • Advantages: fast, keeps old file around, can be put in a shell script
    • Disadvantages: cannot replace existing file, syntax is a little hard to get used to

  2. Using ed:
    ed file
    ,s/ *$//             # the leading comma is VERY IMPORTANT
    wq
    
    • Advantages: fairly fast, replaces existing file
    • Disadvantages: does not keep old file around, even more cryptic than sed technique

  3. XEDIT: You can XEDIT the BFS file and save the file. Make sure you type SAVE or FILE if you don't make any other changes. XEDIT strips the blanks because XEDIT does not retain trailing blanks.

    • Advantages: replaces existing file, easy and probably familiar to use
    • Disadvantages: does not keep old file around; may not work on very large files due to lack of virtual storage or space in the BFS

      Caution: If you are using XEDIT and go into hex mode, it may appear to you that there are trailing blanks on every line. Do not be deceived. XEDIT always pads the edit buffer with trailing blanks, whether or not the original file had trailing blanks. It is when the file gets written back to disk that the blanks are removed.


For more questions and answers, go to our archive of questions and answers.