Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2004
    Posts
    45

    Unanswered: 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

  2. #2
    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> |
    +-----------------------+

  3. #3
    Join Date
    Jul 2004
    Posts
    45
    Awesome!! Thank You!

  4. #4
    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

  5. #5
    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> |
    +-----------------------+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •