[an error occurred while processing this directive]

HP OpenVMS Systems

ask the wizard
Content starts here

Removing Spaces from File Records?

» close window

The Question is:

 
How do I convert a fixed length file that is padded with spaces to a variable
 length file with the trailing spaces removed?
 


The Answer is :

In perl the solution would be:
 
perl -e "while (<>) { s/\s+$/\n/; print }" < input-file > trimmed-file
 
Using DCL it could look like:
 
@trim input-file trimmed-file
 
where trim.com contains:
 
$if p2.eqs."" then exit
$open/read input 'p1
$crea 'p2
$open/appen output 'p2
$record_loop:
$ read/end=done input record
$ l = f$len(record)
$space_loop:
$ l = l - 1
$ if f$extract(l,1,record).eqs." " then goto space_loop
$ write output f$extract(0,l+1,record)
$ goto record_loop
$done:
$ close input
$ close output
$ exit
 

answer written or last revised on ( 6-JAN-2004 )

» close window