The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Stripping a portion of string from behind!!! kumarsaravana_s UNIX for Dummies Questions & Answers 5 03-18-2007 02:21 PM
Please Help!! Reading a string of text with concurrent spaces into a shell variable mjs3221 UNIX for Advanced & Expert Users 1 08-16-2006 02:17 PM
Stripping leading spaces on right justified name Marcia P UNIX for Dummies Questions & Answers 2 02-28-2006 10:32 PM
Variable has spaces around the string, need to remove them mikey20 Shell Programming and Scripting 4 10-13-2005 08:09 PM
Strip leading and trailing spaces only in a shell variable with embedded spaces jerardfjay Shell Programming and Scripting 6 03-07-2005 02:24 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-27-2008
rag84dec rag84dec is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 7
Stripping the spaces in a string variable

Hi ,
i have to strip the spaces in the string which has the following value
Code:
    ABC                           DEF
i want this to appear like this
Code:
ABC DEF
is there any spilt method?
please help....


Thanks
  #2 (permalink)  
Old 03-27-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
man tr, in particular the -s option

Also if you have a value in a variable, simply echoing it will normalize the spacing if you don't quote it (but this has other risks if the string value might contain special characters).
  #3 (permalink)  
Old 03-27-2008
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
in Perl:
Code:
my $str = "ABC                           DEF";
$str =~ s/\s{2,}/ /g;    # substitute two or more spaces with a single one, globally
  #4 (permalink)  
Old 03-27-2008
sparcguy sparcguy is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2006
Posts: 315
in vi mode

:%s/ / /g

essentially every 2 spaces in the file change to 1 space
Closed Thread

Bookmarks

Tags
perl, vim

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:06 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0