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 > 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 06: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 06: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 01:00 PM
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 06:29 AM
How to replace a word with a series of words in a file brap45 Shell Programming and Scripting 2 02-21-2006 02:33 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-22-2006
bryan bryan is offline
Registered User
  
 

Join Date: Jan 2005
Posts: 22
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 (permalink)  
Old 05-22-2006
hu$h's Avatar
hu$h hu$h is offline
Registered User
  
 

Join Date: May 2006
Posts: 17
awk <search pattern> {<program actions>}

http://www.vectorsite.net/tsawk.html
  #3 (permalink)  
Old 05-22-2006
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,211
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 (permalink)  
Old 05-22-2006
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
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 (permalink)  
Old 05-23-2006
bryan bryan is offline
Registered User
  
 

Join Date: Jan 2005
Posts: 22
Thanks Guys
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 07:12 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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