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!

how can I remove trailing space in

Status
Not open for further replies.

PuPPeT2

Programmer
Jul 28, 2003
5
US
how can I remove trailing space in the name variable in the following script:
cat flinf|$search1|$search2| awk '
{
ref_cmd=substr($0,34,20)
if ($0~/\.txt/) {
name=substr($0,4,12)
file_no=substr($0,1,3)
volume=substr($0,17,3)
site=substr($0,4,3)
print "Reformatting file: "file_no" "name":backup "name":"vol
system("reformat "name":backup "name":"volume" " ref_cmd )
}
}'

The name variable is taken from a 12 character subtring in the list, but may contain fewer thatn 12 characters. Outside of awk it is easy. There has to be a way inside awk given the current format of the command. Any ideas?
 
sub("[ ]*$", "", name);


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
thanks vlad, I kept trying to use sub, but tried to add it into the name= line somehow. just as an additional line afterwards and it works fine.

sometimes i feel like i should have been a florist or something other than a programmer. thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top