fetch string and insert later


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting fetch string and insert later
# 1  
Old 07-17-2008
Error 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  
Old 07-17-2008
Try something like this,

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


Thanks
Nagaraj G
# 3  
Old 07-17-2008
Does it need to be using sed? I don't think that's straightforward...
# 4  
Old 07-17-2008
Quote:
Originally Posted by ennstate
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  
Old 07-17-2008
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  
Old 07-17-2008
Quote:
Originally Posted by Annihilannic
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  
Old 07-17-2008
Sorry, I can't make sense of what you typed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert a user input string after matched string in file

i am having file like this #!/bin/bash read -p 'Username: ' uservar match='<color="red" />' text='this is only a test so please be patient <color="red" />' echo "$text" | sed "s/$match/&$uservar\g" so desireble output what i want is if user type MARIA this is only a test so please... (13 Replies)
Discussion started by: tomislav91
13 Replies

2. UNIX for Beginners Questions & Answers

To Fetch values from String

Dears, I have string like below in my csv file <someTechnicalDetails><someTechnicalDetails>HSI</someTechnicalDetails,1234564 <someTechnicalDetails><someTechnicalDetails>Voice</someTechnicalDeta,12345673 <someTechnicalDetails><someTechnicalDetails>IPTV</someTechnicalDetai,12345673 and I... (2 Replies)
Discussion started by: mirwasim
2 Replies

3. Shell Programming and Scripting

Insert String every n lines, resetting line counter at desired string

I need to read a text file and insert a string every n lines, but also have the line counter restart when I come across a header string. Line repeating working every 3 lines using code: sed '0~3 s/$/\nINSERT/g' < INPUT/PATH/FILE_NAME.txt > OUTPUT/PATH/FILE_NAME.txt I cannot seem to find... (1 Reply)
Discussion started by: Skonectthedots
1 Replies

4. Shell Programming and Scripting

Fetch Valid String

Hi All, How to fetch the particular row based on my search command. For example Source Column Column A Column B 001,56123456 002,57123456 003,123456 Expected Output: 003,123456 To get this output I tried below mentioned function grep '123456' filename.txt (4 Replies)
Discussion started by: suresh_target
4 Replies

5. Shell Programming and Scripting

Need to insert a comment string

I need to insert a comment string to a couple of fields for every line in the file. Different comment string for each field. In below file, fields 7 and 8 "R","1","t0000684","","10/31/2013","10/31/2013","","","","750.23"... (6 Replies)
Discussion started by: Melah Gindi
6 Replies

6. Shell Programming and Scripting

Cut & Fetch word from string

I have a file with some SQL query, I want to fetch only Table Name from that file line by line. INPUT FILE SELECT * FROM $SCHM.TABLENAME1; ALTER TABLE $SCHM.TABLENAME1 ADD DateOfBirth date; INSERT INTO $SCHM.TABLENAME1 (CustomerName, Country) SELECT SupplierName, Country FROM $SCHM.TABLENAME2... (2 Replies)
Discussion started by: Pratik Majithia
2 Replies

7. Shell Programming and Scripting

How to fetch a string between two different strings?

Hi I am having a file with content as, <name>usrname</name> <value>ravistej</value> <name>pswd</name> <value>asdfgzxcv</value> . . . . <name>abc</name> <value>xyz</value> From this file, i want to fetch the string present between '<value>' and '</value>' and store the values into... (9 Replies)
Discussion started by: tejastrikez
9 Replies

8. Shell Programming and Scripting

Fetch the rows with match string on a fixed lenth text file - NO delimiters

Hi I am trying to fetch the rows with match string "0000001234" Input file looks like below: 09 0 XXX 0000001234 Z 1 09 0 XXX 0000001234 Z 1 09 0 XXX 0000001234 Z 1 09 0 XXX 0000001234 Z 1 09 0 XXX 0000001234 Z 1... (6 Replies)
Discussion started by: nareshk
6 Replies

9. Shell Programming and Scripting

How to fetch variable value in if block and to compare it with certain string

Hi, I am trying to execute this command if ; then but getting error .Some problem with reteriving the value of $exception_info. Please help.Its urgent. thanks (4 Replies)
Discussion started by: khushboo
4 Replies

10. Programming

vector<string> with insert cmd

How do I correct this vector<string> insert. I am geeting segmintation dump. #include <algorithm> #include <cstdio> #include <cstdlib> #include <cctype> #include <cmath> #include <iostream> //#include <sstream> #include <string> #include <utility> #include <vector> using... (1 Reply)
Discussion started by: photon
1 Replies
Login or Register to Ask a Question