return a word between two words


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers return a word between two words
# 1  
Old 05-22-2006
return a word between two words

how do i get a word that exists between two words

eg: this is bryan
My input to command would be this and bryan
and output should be 'is'

Is there a command i can use?
# 2  
Old 05-22-2006
awk <search pattern> {<program actions>}

http://www.vectorsite.net/tsawk.html
# 3  
Old 05-22-2006
Quote:
Originally Posted by bryan
how do i get a word that exists between two words

eg: this is bryan
My input to command would be this and bryan
and output should be 'is'

Is there a command i can use?

Code:
sed -n 's/word1[ ][ ]*\([^ ]*\)[ ][ ]*/\1/p'

# 4  
Old 05-22-2006
Try...
Code:
eg="eg: this is bryan"
w1="this"
w2="bryan"
result=$(echo $eg | awk -v w1="$w1" -v w2="$w2" 'match($0, w1 ".*" w2){
   print substr($0,RSTART+length(w1),RLENGTH-length(w1 w2))}')
echo $result

# 5  
Old 05-23-2006
Thanks Guys
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract words before and after a certain word.

I have a sample text file with file name: sample.txt The text file has the following text. this is an example text where we have to extract certain words before and after certain word these words can be used later to get more information I want to extract n (a constant) words before and... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

2. Shell Programming and Scripting

Search a column a return a set of words

Hi I have two files. One is a text file consisting of sentences i.e. INPUT.txt and the second file is SEARCH.txt consisting of two or three columns. I need help to write a script to search the second column of SEARCH.txt for each set of five words (blue color as set one and green color as set... (6 Replies)
Discussion started by: my_Perl
6 Replies

3. UNIX for Dummies Questions & Answers

Replacing word and Capitalize words after

I have an assignment and I am not sure what to do. In Unix, I use PuTTY change the semicolon (;) to a period, and capitalize the first letter of the word immediately after it. I know change command is M-% and "." so only one semicolon is changed but I am not sure how to... (1 Reply)
Discussion started by: kathrut43
1 Replies

4. UNIX for Dummies Questions & Answers

How to return only specific words in a line?

Hi, I'm a bash newbie and have a data set like this idxxx1 something something marker_id_132=rsxxx;marker_id_135=rsxxx idxxx2 something something marker_id_132=rsxxx;marker_id_135=rsxxx idxxx3 something something marker_id_132=rsxxx;marker_id_135=rsxxx ... ... (7 Replies)
Discussion started by: hanhel
7 Replies

5. Shell Programming and Scripting

Need help in search for word and return line

Hi, I have this file format and can't seem to think of a solution. I need your help. I want to return lines which says "Record" if it's ID > 0 file.txt Record 1: :::::::::::::::::::::: :::::::::::::::::::::: ID "000001" :::::::::::::::::::::: :::::::::::::::::::::: ... (6 Replies)
Discussion started by: jakSun8
6 Replies

6. Shell Programming and Scripting

How to get a known word between two known words using awk

hi I have posted it earlier but i was unable to put my exact problem.This time posting in parts. I have a text file which i had transferred to UNIX.It has strings like: alter table table_name add (column_name); as well as modify options. now i need to read the table name between alter... (3 Replies)
Discussion started by: alisha
3 Replies

7. Shell Programming and Scripting

Print all the words after a match word

Hi, I want to print all words till the last word after the match of "ERROR" word. For e.g. I'll get an sqlplus error with e.g. 1 $ ./calltest_fn.ksh var test_var:=test_fn1; calltest_fn.ksh file1 file2 file3 ERROR at line 4: ORA-06550: line 4, column 11: PLS-00201: identifier... (5 Replies)
Discussion started by: dips_ag
5 Replies

8. Shell Programming and Scripting

Split a word in short words

Dear, Can somebody help me with this? I have a variable TGT=T2DIRUPDAZ20070326VA I want to get in variables some part of TGT. like this. TGT1=UPDA TGT2=20070326 TGT3= VA These three variables have fixe position in variable TGT. (2 Replies)
Discussion started by: yeclota
2 Replies

9. UNIX for Advanced & Expert Users

How to filter the words, if that word contains the expected letter

Hi, I am trying to filter the words from a file which contain 'abc'. But I am unable to. Could any one help me. For eg: The file contents are 123ab 12hnj1 123abc456 123cgbcahjkf23 23134abchfhj43 gc32abc abc1 2abc3 sd uiguif fhwe 21242 uh123 jkcas124d123 u3hdbh23u ffsd8 Output... (3 Replies)
Discussion started by: venu_eie
3 Replies

10. Shell Programming and Scripting

How to replace a word with a series of words in a file

Hi, I have a Template file 'TL.body' which says as follows: "There are no <FILENAME> files on the server. " The missing file names are identified and stored in a variable. For Eg: MISSFILE="abc.txt def.txt xyz.txt" I want the values of MISSFILE variable to be replaced against... (2 Replies)
Discussion started by: brap45
2 Replies
Login or Register to Ask a Question