- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Replace 1 or multiple spaces or tabs with a si...
Categories
Company
Local Language
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
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
Community
Resources
Forums
Blogs
- 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
тАО12-20-2006 01:40 AM
тАО12-20-2006 01:40 AM
First, I'm using standard POSIX Shell. Not Bash.
Additionnally, it's HP's standard sed also. Not GNU Sed.
I'm trying to replace 1 or more spaces/tabs with a single on each occurrence.
In Perl, I think it would be something like this:
s/\s+/ /g
'\s' being recognize has either a space or tab.
I can't make it work with HPUX 11.11 or 11.23 sed. My script is already written in shell, so I was hopping not to go Perl.
Thanks.
Patrick
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-20-2006 01:47 AM
- Tags:
- tr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-20-2006 01:49 AM
тАО12-20-2006 01:49 AM
Re: Replace 1 or multiple spaces or tabs with a single space
Try using tr instead.
tr -s [:space:] " "
will do what you want. To use tr you can do:
tr -s [:space:] " " < testfile
To get the output to a file:
tr -s [:space:] " " < testfile > testfile.new
you can also do:
cat testfile | tr -s [:space:] " " > testfile2
You have all kinds of options.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-20-2006 01:50 AM
тАО12-20-2006 01:50 AM
Re: Replace 1 or multiple spaces or tabs with a single space
Give 'tr -s ...' a try:
$ tr -s " \t" " " < filein > fileout
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-20-2006 01:52 AM
тАО12-20-2006 01:52 AM
Re: Replace 1 or multiple spaces or tabs with a single space
this will do it (it's [spaceTAB]):
sed '/s[
Enter a real tab for
If you don not want to convert TAB(s) to space (like in your example), but to a single TAB, use - untested -
sed -e 's/ */ /g' -e 's/ *
First is 'spacespace*', last is 'space*TABTABspace*'.
mfG Peter
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-20-2006 02:10 AM
тАО12-20-2006 02:10 AM
Re: Replace 1 or multiple spaces or tabs with a single space
tr -s [:space:] " " didn't work for me. Had tried it like that, but doesn't do it.
You somehow need 2 set of square brakets: [[:space:]]
That did it.
Thanks again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-20-2006 02:24 AM
тАО12-20-2006 02:24 AM
Re: Replace 1 or multiple spaces or tabs with a single space
Please consider assigning points for the help you have been offered in this and your other threads as listed in your profile.
...JRF...