- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: how to get rid of trailing white spaces using ...
Operating System - HP-UX
1753785
Members
7541
Online
108799
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-17-2005 09:10 PM
тАО03-17-2005 09:10 PM
Re: how to get rid of trailing white spaces using awk
Fernando -- I'm making the assumption that you only want to get rid of white space at the end of the line.
sample data input (add three spaces after last word):
Fernando Fulgar Fernando
To test:
wc indata
1 3 30
{NOTE: one character is a carriage return)
Create a file, tw.awk, with this script in it:
{dalen=length($0);daflag=0;
for (idx1=dalen;daflag==0;idx1--)
{ if (substr($0,idx1,1)!=" ")
{print substr($0,1,idx1);exit}
}
}
awk -f tw.awk < indata > outdata
wc -l outdata
1 3 27 outdata
best regards,
Kent M. Ostby
sample data input (add three spaces after last word):
Fernando Fulgar Fernando
To test:
wc indata
1 3 30
{NOTE: one character is a carriage return)
Create a file, tw.awk, with this script in it:
{dalen=length($0);daflag=0;
for (idx1=dalen;daflag==0;idx1--)
{ if (substr($0,idx1,1)!=" ")
{print substr($0,1,idx1);exit}
}
}
awk -f tw.awk < indata > outdata
wc -l outdata
1 3 27 outdata
best regards,
Kent M. Ostby
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-18-2005 07:07 AM
тАО03-18-2005 07:07 AM
Re: how to get rid of trailing white spaces using awk
I like perl a lot, but in this case there is a perfectly reasonable, compact, readable awkward solution as requested.
As I replied earlier, but I guess is got overlooked, just use the SUBstitute function using "any number of spaces at end of variable" as ere (extended regular expression) and nothing ("") as replacement string on the variable of choice.
This case $2, and often you can just work on $0.
Solution:
sub(/ *$/,"",$2)
Cheers,
Hein.
As I replied earlier, but I guess is got overlooked, just use the SUBstitute function using "any number of spaces at end of variable" as ere (extended regular expression) and nothing ("") as replacement string on the variable of choice.
This case $2, and often you can just work on $0.
Solution:
sub(/ *$/,"",$2)
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-18-2005 09:59 AM
тАО03-18-2005 09:59 AM
Re: how to get rid of trailing white spaces using awk
If possible, i would rather use sed to get rid of heading and trailing spaces:
sed -e "s/^[ \t]*//; s/[ \t]*$//;"
Regards,
Alex
sed -e "s/^[ \t]*//; s/[ \t]*$//;"
Regards,
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-20-2005 07:14 PM
тАО03-20-2005 07:14 PM
Re: how to get rid of trailing white spaces using awk
dear all,
it was a great help!
many thanks!
it was a great help!
many thanks!
- « Previous
-
- 1
- 2
- Next »
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP