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
Can I use sed to insert a string which has colon Jenny.palmy UNIX for Dummies Questions & Answers 2 04-28-2008 07:04 PM
How to insert a string at the end of a file read ahjiefreak Shell Programming and Scripting 5 12-10-2007 11:38 PM
how to insert line break + string in vi (search & replace ) umen Shell Programming and Scripting 1 06-08-2006 11:42 AM
Failed to insert string into file before line nir_s Shell Programming and Scripting 7 07-26-2005 01:37 AM
vector<string> with insert cmd photon High Level Programming 1 09-10-2004 05:51 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 07-17-2008
playinmel.com playinmel.com is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 3
Exclamation fetch string and insert later

PHP Code:
"are you billy_smith ?" 
replace with

PHP Code:
"are you billy_smith ?
my name is billy_smith" 
how to fetch the name "billy_smith" and using it later
I need sed script to do this, any one can help? Thanks
  #2 (permalink)  
Old 07-17-2008
ennstate ennstate is offline
Registered User
  
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
Try something like this,

Code:
echo "Are you Bill ?" | sed 's/.* \(.*\) ?/My name is \1/g'

Thanks
Nagaraj G
  #3 (permalink)  
Old 07-17-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Does it need to be using sed? I don't think that's straightforward...
  #4 (permalink)  
Old 07-17-2008
playinmel.com playinmel.com is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 3
Quote:
Originally Posted by ennstate View Post
Try something like this,

Code:
echo "Are you Bill ?" | sed 's/.* \(.*\) ?/My name is \1/g'
Thanks
Nagaraj G
Thanks, Can i just get the "name" and set it to $name , so that I can reuse $name later
  #5 (permalink)  
Old 07-17-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
You only have one "variable" in sed, which is called the "hold space". You can copy or append the current "pattern space" to the "hold space", or you can exchange the two, but inserting the contents of one in the middle of the other is difficult.

You would do much better with awk or perl or similar.
  #6 (permalink)  
Old 07-17-2008
playinmel.com playinmel.com is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 3
Quote:
Originally Posted by Annihilannic View Post
You only have one "variable" in sed, which is called the "hold space". You can copy or append the current "pattern space" to the "hold space", or you can exchange the two, but inserting the contents of one in the middle of the other is difficult.

You would do much better with awk or perl or similar.
You are right, Thanks,
there is a .sh file to do replacement.sed
what i can do is to modify the replacement file.
how can i use awk in .sed.
Thanks
  #7 (permalink)  
Old 07-17-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Sorry, I can't make sense of what you typed.
Sponsored Links
Closed Thread

Bookmarks

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 12:15 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