LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 12-06-2003, 03:50 AM   #1
jitz
LQ Newbie
 
Registered: Nov 2003
Distribution: Red Hat
Posts: 8

Rep: Reputation: 0
Pattern search in a line


Is there a way to get the words in between two given patterns from a single line
 
Old 12-06-2003, 04:37 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
This is a solution:
Code:
#!/bin/bash

TESTLINE="Unix and linux are great and wonderfull operating systems."

PATTERN_1="are"
PATTERN_2="operating"

echo "Original:"
echo "${TESTLINE}"
echo ""
echo "Words in between two patterns ('are' and 'operating'):"
echo ${TESTLINE} | sed "s/.*${PATTERN_1}\(.*\)${PATTERN_2}.*/\1/"
 
Old 12-06-2003, 04:50 AM   #3
jitz
LQ Newbie
 
Registered: Nov 2003
Distribution: Red Hat
Posts: 8

Original Poster
Rep: Reputation: 0
Thnks a lot buddy
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 06:17 AM
What is the Package Search pattern Syntax for dpkg --list? Akhran Debian 3 08-23-2005 05:23 AM
pattern search through find command. abhi Linux - Newbie 2 04-11-2005 10:31 AM
search for pattern in files and replace mizuki26 Linux - Newbie 3 01-04-2004 11:57 AM
multiline pattern search in a file mimi Linux - General 1 09-01-2002 12:22 PM


All times are GMT -5. The time now is 05:09 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration