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!

Trimming Tabs from data fields 1

Status
Not open for further replies.

arcticpuppy

Technical User
Jan 14, 2003
8
US
I currently use this function to trim spaces from a string
function trim(str){
nsub1=sub("^[ ]*", "", str)
nsub2=sub("[ ]*$", "", str)
return str
}

I tried to use
nsub1=sub("^[ ]*", "\t", str)
nsub3=sub("[ ]*$", "\t", str)

to remove tabs and only was able to remove "tt" from my strings....does anyone have a asuggestion on how to remove leading tabs and following tabs from a string ?
 
In a Vi session, try keying Cntrl V M (Holding Ctrl & V them typing M) - You should end up with ^M ( occupies 1 space) and is resolved as a tab. Also see thread822-494530 Dickie Bird (:)-)))
 
function trim(str){
sub("^[ \t]*", "", str)
sub("[ \t]*$", "", str)
return str
}
vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
why not:

sed -e 's/^[spacetab]*[spacetab]//' input >ouput

space is a really pressed space-char
tab is a really pressed tab-char

dickiebird : ^M is a newline not a tab, :(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top