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
Remove spaces between charc and replace it with ','. smc3 Shell Programming and Scripting 5 06-10-2008 12:08 PM
Replace spaces recursively prvnrk Shell Programming and Scripting 5 08-31-2007 04:37 AM
Replace blank spaces by single tab, and right alignment Jae Shell Programming and Scripting 1 08-08-2007 10:58 PM
Replace spaces with 0's having numeric values. videsh77 Shell Programming and Scripting 1 04-15-2005 01:22 AM
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
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-06-2008
tret tret is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 29
Replace spaces

Hi guys, so I have another issue. Can I use sed to replace spaces in a string or variable with %20

I am having trouble with using curl on URL's containing spaces

Thanks!
  #2 (permalink)  
Old 10-06-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,382
post sample input and output record
  #3 (permalink)  
Old 10-06-2008
cfajohnson's Avatar
cfajohnson cfajohnson is online now Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,317
Quote:
Originally Posted by tret View Post
Hi guys, so I have another issue. Can I use sed to replace spaces in a string or variable with %20

I am having trouble with using curl on URL's containing spaces

Code:
string=$( printf "%s\n" "$string" | sed 's/ /%20/g' )
Or. with bash or ksh93:

Code:
string=${string// /%20}
  #4 (permalink)  
Old 10-06-2008
tret tret is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 29
Quote:
Originally Posted by vidyadhar85 View Post
post sample input and output record
this is a sample of the code I have to get the file "GetSeries.php.xml" from thetvdb.com

Code:
series_name="green hornet"

curl -s -o /Users/rtipton/Desktop/GetSeries.php.xml "http://thetvdb.com/api/GetSeries.php?seriesname=$series_name"
When I run this, I get a bunch of results in the xml for tv shows including "green" in the title. Curl doesn't include anything after the first space in the URL.

I'm not sure what output I could provide in this instance, let me know if I can give more

Thanks again Vid
  #5 (permalink)  
Old 10-06-2008
tret tret is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 29
Quote:
Originally Posted by cfajohnson View Post

Code:
string=$( printf "%s\n" "$string" | sed 's/ /%20/g' )
Or. with bash or ksh93:

Code:
string=${string// /%20}
Hey thanks cfajohnson, that did the trick, the second suggestion works perfectly!

Thanks again for being so helpful guys, I really appreciate it.
  #6 (permalink)  
Old 10-06-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,382
you can try something like this
Code:
 
series_name=`echo "$series_name"|sed 's/ /%20/g'`
  #7 (permalink)  
Old 10-06-2008
tret tret is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 29
Quote:
Originally Posted by vidyadhar85 View Post
you can try something like this
Code:
 
series_name=`echo "$series_name"|sed 's/ /%20/g'`
Nice this works as well. Too many good options here! You guys are good, thanks again!

Rob
Sponsored Links
Closed Thread

Bookmarks

Tags
unix commands

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 09:37 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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