Removing trailing blanks 
Author Message
 Removing trailing blanks

Hi,

anyone out there have a nice way of removing trailing blanks from
fields obtained from fixed recordformats by substr()  ??



Tue, 15 Feb 2000 03:00:00 GMT  
 Removing trailing blanks

Quote:

> anyone out there have a nice way of removing trailing blanks from
> fields obtained from fixed recordformats by substr()  ??

sub("[ \t]+$", "", $1)

--



Tue, 15 Feb 2000 03:00:00 GMT  
 Removing trailing blanks

: anyone out there have a nice way of removing trailing blanks from
: fields obtained from fixed recordformats by substr()  ??

{ $1=$1""; print }

If your awk doesn't remove redundant whitespace with that (many don't), use:

{ gsub(/[ ]+/," "); print }

The latter requires a more modern awk, try nawk/gawk if yours hacks on gsub().
(My suspicion is that the latter is slower, but I did not benchmark)
--



Tue, 15 Feb 2000 03:00:00 GMT  
 Removing trailing blanks

Quote:

> anyone out there have a nice way of removing trailing blanks from
> fields obtained from fixed recordformats by substr()  ??

A simple user-defined function named Trim() is a nice way:

function Trim(string) {
    sub(/^[[:space:]]/, "", string)
    sub(/[[:space:]]+/, "", string)
    return string

Quote:
}

Replace the character class [[:space:]] with whatever regular
expression fits your definition of "blanks" and works with your
version of awk.

--
Jim Monty

Tempe, Arizona USA



Tue, 15 Feb 2000 03:00:00 GMT  
 Removing trailing blanks

: Hi,

: anyone out there have a nice way of removing trailing blanks from
: fields obtained from fixed recordformats by substr()  ??

How about sub(/ +$/, "", whatever)?



Tue, 22 Feb 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. how to remove trailing blanks of a string?

2. J for delete trailing blanks[Q]

3. Stripping leading and trailing blanks - How?

4. File Conversion: UNIX.txt to DOS.txt and trim trailing blanks

5. Way to find the trailing blanks

6. trailing blanks format?

7. Modifying existing script to remove trailing newlines

8. Remove trailing newlines from file

9. removing trailing spaces from string variables

10. Removing trailing spaces from a field using awk

11. Elisp--Remove a trailing NULL char?

12. Removing data between blank lines

 

 
Powered by phpBB® Forum Software