The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's manas6 UNIX for Dummies Questions & Answers 0 06-05-2008 03:44 AM
Display most top 10 occurring words along with number of ocurences of word inthe text smacherla Shell Programming and Scripting 2 05-23-2008 03:12 PM
How to filter the words, if that word contains the expected letter venu_eie UNIX for Advanced & Expert Users 3 03-19-2008 09:00 AM
Can a shell script pull the first word (or nth word) off each line of a text file? tricky Shell Programming and Scripting 5 08-17-2006 03:29 AM
How to replace a word with a series of words in a file brap45 Shell Programming and Scripting 2 02-20-2006 10:33 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-22-2006
Registered User
 

Join Date: Jan 2005
Posts: 22
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-22-2006
hu$h's Avatar
Registered User
 

Join Date: May 2006
Posts: 17
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
awk <search pattern> {<program actions>}

http://www.vectorsite.net/tsawk.html
Reply With Quote
  #3 (permalink)  
Old 05-22-2006
reborg's Avatar
Administrator
 
Join Date: Mar 2005
Location: Ireland
Posts: 3,407
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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'
Reply With Quote
  #4 (permalink)  
Old 05-22-2006
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,207
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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
Reply With Quote
  #5 (permalink)  
Old 05-23-2006
Registered User
 

Join Date: Jan 2005
Posts: 22
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Thanks Guys
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:43 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101