Original post is here: eklausmeier.goip.de
On MVS there are mainly VB and FB files. This is abbreviated RECFM=VB or RECFM=FB (record format). VB files are variable block, each record in the file contains a 4-byte header for the length information. FB are fixed block, each record having a fixed number of bytes. The record length is abbreviated with LRECL (logical record length).
When you process FB files on Linux and want to work with them with wc
, grep
, cut
, etc., then you have to convert them beforehand. This means every fixed length record needs a finishing '\n'
byte at the end. Also, you usually you want to get rid of all the space character at the end of the line. I.e., you want to trim each line.
Below short C program does just that. Each record is terminated with a newline character. Additionaly, each line is trimmed.
1/* Every 32.000 bytes insert a newline, this number can be changed with command line flag -c
2 Trim space at end of line
3*/
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <unistd.h>
8
9int main(int argc, char *argv[]) {
10 int c, i, k, reclen=32000;
11 FILE *fp = NULL;
12
13 while ((c = getopt(argc,argv,"c:")) != -1) {
14 switch (c) {
15 case 'c':
16 reclen = atoi(optarg);
17 break;
18 default:
19 printf("Illegal command line flag: %c\n",c);
20 break;
21 }
22 }
23
24 if (optind >= argc) fp = stdin;
25 if (fp != stdin && (fp = fopen(argv[optind],"r")) == NULL) {
26 printf("Cannot open %s\n",argv[optind]);
27 return 1;
28 }
29
30 i = reclen; // number of char's
31 k = 0; // number of spaces
32 while ((c = fgetc(fp)) != EOF) {
33 if (c == ' ') ++k;
34 else {
35 //printf("(k=%d)",k);
36 for (; k>0; --k) putchar(' ');
37 putchar(c);
38 }
39 if (--i <= 0) {
40 i = reclen;
41 k = 0;
42 putchar('\n');
43 }
44 }
45
46 if (fp != stdin) fclose(fp);
47
48 return 0;
49}
Example usage:
1printf "ab cde fg" | corefixedblock -c4
2ab c
3de f
4g%