LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 08-19-2009, 03:18 PM   #1
bpwoods
LQ Newbie
 
Registered: Aug 2009
Posts: 9

Rep: Reputation: 0
sed & piping (solved)


Because of the way the app was written I have some odd limitations. So I realize there are easier ways to do what I want, but I kind of need to make this work.

So I have a files text that is moving though a pipe. So, I want to replace all of the spaces with a ‘+’ after a point in the string. I have to do it in the pipe, and move it to the next command. So multiple commands are a no go.

What I was trying:
Code:
echo "URL: http://www.google.com/hello world 1 2 3" | sed 's/http:\(.*\) /\1+/'
But it only replaces it once:
Code:
URL: //www.google.com/hello world 1 2+3
I though, “Ok, so I will just run it though the same command.
Code:
echo "URL: http://www.google.com/hello world 1 2 3" | sed 's/http:\(.*\) /\1+/' | sed 's/http:\(.*\) /\1+/'
No change:
Code:
URL: //www.google.com/hello world 1 2+3
Scratched my head for a sec, then did this:
Code:
echo "URL: http://www.google.com/hello world 1 2 3" | sed 's/http:\(.*\) /\1+/' | sed 's/ttp:\(.*\) /\1+/'
And got:
Code:
URL: //www.google.com/hello world 1+2+3
Why can’t you do multiple ?stages? in the pip with sed? Am I missing something?

Same for:
Code:
echo "URL: http://www.google.com/hello world 1 2 3" | sed 's/http:\(.*\) /\1+/' | sed 's/ttp:\(.*\) /\1+/' | sed 's/http:\(.*\) /\1+/'

Last edited by bpwoods; 08-19-2009 at 03:37 PM.
 
Old 08-19-2009, 03:36 PM   #2
bpwoods
LQ Newbie
 
Registered: Aug 2009
Posts: 9

Original Poster
Rep: Reputation: 0
DOH!

Ok, sorry, solved:

Code:
echo "URL: http://www.google.com/hello world 1 2 3" | sed 's/http:\(.*\) /http:\1+/' | sed 's/http:\(.*\) /http:\1+/'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Piping output fm cut into sed wtaicken Programming 7 12-09-2008 10:54 AM
smrsh & sendmail error when piping digity Linux - General 1 04-16-2005 01:11 PM
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-03-2005 11:00 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM
Shell scripting & piping dimavo Programming 8 04-24-2003 05:27 PM


All times are GMT -5. The time now is 11:52 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration