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

    Join Date
    Mar 2017
    Posts
    4
    Rep Power
    0

    Extract string between pipes


    Hi All,

    I need your help to extract string between pipes.

    what I what to extract is the text "User Signed Out" from the following part as an event name |601|User Signed Out|3|src

    the complete log message is :-

    Trend Micro|Deep Security Manager|9.5.6511|601|User Signed Out|3|src=xx.xxx.xx.xx
    suser=System target=home_check msg=Description Omitted
    TrendMicroDsTenant=Primary TrendMicroDsTenantId=0

    Thanks,
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,473
    Rep Power
    1875
    Which regex syntax do you want?
    BRE/ERE/Perl?

    https://en.wikipedia.org/wiki/Regula...c_and_extended

    You could do it simply with
    Code:
    awk -F'|' '{ print $5 }' logfile
    if you wanted.
    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
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2017
    Posts
    4
    Rep Power
    0
    Thanks Salem,

    I don't want to use awk , I just need to grep this string with regex pattern

    Thanks
  6. #4
  7. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,473
    Rep Power
    1875
    But grep just finds things and prints the whole line containing the matches.

    If you want to extract it and feed it to something else, then you need sed/awk/perl like tools.
    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
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2017
    Posts
    4
    Rep Power
    0
    You did not get my point

    I just need to extract the text without any command lines just like as using https://regex101.com/
  10. #6
  11. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,473
    Rep Power
    1875
    Maybe this
    Code:
    \d+\|[^|]+\|\d+
    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
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2017
    Posts
    4
    Rep Power
    0
    I tried this regex (?<=\|)[^|]++(?=\|)
    however I need to match the fourth result only
    could it be done ?

IMN logo majestic logo threadwatch logo seochat tools logo