#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0

    SED command issue


    Hi All,

    I'm facing a issue with my SED command where I need to extract a value from a grep command output. I'm able to extract the value, just that the initial character which i need is not getting extracted.

    I pipe the ps and grep command and on output one of line is

    Command: ps -ef|grep web-ELISA

    -Xloggc:/apps/inventory/qa/deploy/inventory-web/invt-tomcat-instance-invt-5.06.008-web-ELISA-qa/logs/garbage_collector.log -Dcom.sun.management.jmxremote

    This has my application log location.

    To extract the exact log location i need to extract the following text alone.

    /apps/inventory/qa/deploy/inventory-web/invt-tomcat-instance-invt-5.06.008-web-ELISA-qa/logs/

    so i use I used sed command with pipe option

    command: ps -ef | grep web-ELISA | ps -ef|grep -E web-EY | sed -n "s/.*\(.*apps.*logs\).*/\1/p"

    I'm getting the response as
    apps/inventory/qa/deploy/inventory-web/invt-tomcat-instance-invt-5.06.008-web-ELISA-qa/logs/

    The initial character which I need is '/' which is not comming as expected. Even i tried following command with *\apps instead of \apps

    command: ps -ef | grep web-ELISA | ps -ef|grep -E web-EY | sed -n "s/.*\(.*\apps.*logs\).*/\1/p"

    Regards,
    Ramkumar
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0
    Even if we have solution to concatenate '/' to the return response and doing a chage directory[cd] command is also fine.

    Regards,
    Ramkumar


    Originally Posted by ramkumar.siva
    Hi All,

    I'm facing a issue with my SED command where I need to extract a value from a grep command output. I'm able to extract the value, just that the initial character which i need is not getting extracted.

    I pipe the ps and grep command and on output one of line is

    Command: ps -ef|grep web-ELISA

    -Xloggc:/apps/inventory/qa/deploy/inventory-web/invt-tomcat-instance-invt-5.06.008-web-ELISA-qa/logs/garbage_collector.log -Dcom.sun.management.jmxremote

    This has my application log location.

    To extract the exact log location i need to extract the following text alone.

    /apps/inventory/qa/deploy/inventory-web/invt-tomcat-instance-invt-5.06.008-web-ELISA-qa/logs/

    so i use I used sed command with pipe option

    command: ps -ef | grep web-ELISA | ps -ef|grep -E web-EY | sed -n "s/.*\(.*apps.*logs\).*/\1/p"

    I'm getting the response as
    apps/inventory/qa/deploy/inventory-web/invt-tomcat-instance-invt-5.06.008-web-ELISA-qa/logs/

    The initial character which I need is '/' which is not comming as expected. Even i tried following command with *\apps instead of \apps

    command: ps -ef | grep web-ELISA | ps -ef|grep -E web-EY | sed -n "s/.*\(.*\apps.*logs\).*/\1/p"

    Regards,
    Ramkumar
  4. #3
  5. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,388
    Rep Power
    1871
    You seem to be getting your / and \ all mixed up.

    That / is also the command separator for the s command isn't helping.

    Fortunately, you can replace the command separator with another char of your choice.

    Eg.
    sed -n "s@.*\(/apps.*logs/\).*@\1@p"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0
    Thanks,

IMN logo majestic logo threadwatch logo seochat tools logo