If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > extracting the word from the pattern

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-27-04, 16:34
deebee deebee is offline
Registered User
 
Join Date: Jul 2004
Posts: 45
extracting the word from the pattern

How can i get the whole string or word from a given pattern. for eg.
for a given line :
$ABC_SH/mycode.sh -v aaa -r /mydir/files/data/ ${MYDIR}/hello.sh $DIR/bin
If my search string MYDIR then i should get ${MYDIR}/hello.sh
thanks in advance
Reply With Quote
  #2 (permalink)  
Old 08-27-04, 16:51
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
Code:
echo '$ABC_SH/mycode.sh -v aaa -r /mydir/files/data/ ${MYDIR}/hello.sh $DIR/bin' | sed -e 's/.* \([^ ][^ ]*MYDIR[^ ][^ ]*\).*/\1/g'
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
  #3 (permalink)  
Old 08-27-04, 17:13
deebee deebee is offline
Registered User
 
Join Date: Jul 2004
Posts: 45
Awesome!! Thank You!
Reply With Quote
  #4 (permalink)  
Old 09-01-04, 16:26
deebee deebee is offline
Registered User
 
Join Date: Jul 2004
Posts: 45
Quote:
Originally Posted by vgersh99
Code:
echo '$ABC_SH/mycode.sh -v aaa -r /mydir/files/data/ ${MYDIR}/hello.sh $DIR/bin' | sed -e 's/.* \([^ ][^ ]*MYDIR[^ ][^ ]*\).*/\1/g'
How can I modify the above to extract if multiple ${MYDIR}/hello.sh exist in the same line
$ABC_SH/mycode.sh -v aaa -r /mydir/files/data/ ${MYDIR}/hello.sh $DIR/bin ${MYDIR}/hi.sh
For eg. (if my pattern is MYDIR )
above should return
${MYDIR}/hello.sh
${MYDIR}/hi.sh
Reply With Quote
  #5 (permalink)  
Old 09-02-04, 10:39
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
nawk -v str='MYDIR' -f deebee.awk myFile.txt

here's 'deebee.awk':
Code:
$0 ~ str {
  for(i=1; i <= NF; i++)
    if ( $i ~ str) 
       print $i
}
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On