how to remove spaces in a string using sed. | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

how to remove spaces in a string using sed.

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-02-2005
radhika radhika is offline
Registered User
 
Join Date: Apr 2005
Last Activity: 2 November 2005, 4:53 PM EST
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
how to remove spaces in a string using sed.

Hello,

I have the following to remove spaces from beginning and end of a string.
infile=`echo "$infilename" | sed 's/^ *//;s/ *$//`

How do I modify the above code to remove spaces from beginning, end and in the middle of the string also.

ex:
Shell Programming is fun
Result should be:
ShellProgrammingisfun


ThankYou,
Radhika.
Sponsored Links
    #2  
Old 06-02-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 30 October 2014, 6:24 PM EDT
Location: Foxborough, MA
Posts: 7,667
Thanks: 152
Thanked 586 Times in 551 Posts
infile=`echo "$infilename" | sed 's/ //g'`
Sponsored Links
    #3  
Old 06-02-2005
radhika radhika is offline
Registered User
 
Join Date: Apr 2005
Last Activity: 2 November 2005, 4:53 PM EST
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
I have one more question- what is a good book for awk, sed, grep, kshell scripting for beginners like me.

ThankYou! for your prompt replies.

Appreciate it!
Radhika.
    #4  
Old 06-02-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 30 October 2014, 6:24 PM EDT
Location: Foxborough, MA
Posts: 7,667
Thanks: 152
Thanked 586 Times in 551 Posts
check out the FAQ and also this thread
Sponsored Links
    #5  
Old 06-02-2005
BCarlson BCarlson is offline
Registered User
 
Join Date: May 2005
Last Activity: 19 October 2006, 9:29 AM EDT
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Bug Unix Book

A book that I've had success with is: UNIX Shells, by Ellie Quigley. It has some typos in it but it's rather good.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remove spaces in the beginning of a string shrutihardas Shell Programming and Scripting 18 05-27-2010 05:03 PM
How to remove extra spaces from a string?? vanitham Shell Programming and Scripting 2 06-02-2009 09:01 AM
sed - remove spaces before 1rst occurence of string danmauer Shell Programming and Scripting 6 01-15-2009 06:23 PM
remove blank spaces in a string spandu Shell Programming and Scripting 2 03-02-2006 01:08 AM
Variable has spaces around the string, need to remove them mikey20 Shell Programming and Scripting 4 10-13-2005 08:09 PM



All times are GMT -4. The time now is 03:39 AM.