Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Field length manipulation question?

Status
Not open for further replies.

DiscoPants

Programmer
Apr 9, 2003
3
GB
Hello, I wonder if anybody can help. I have a large awk program which outputs a list of characters with any number of null spaces between them follwed by a varying number of null spaces., I need to format the output so as to just show the field without the trailing spaces.

For example, I may have:-
'Ab cde fghijk l mnop qr s '

And need to print
'Ab cde fghijk l mnop qr s'

Is there a simple way of doing this, At the moment I can only thing of reading into an array and counting back til I hit the last character

Cheers
 
# ------------------------------------------------------------------------
#
# Function to "trim" leading and trailing spaces from a string NOT
# disturbing the "embedded" spaces.
#
function trim(str)
{
sub("^[ ]*", "", str);
sub("[ ]*$", "", str);
return str;
}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top