Find the answer to your Linux question:
Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By tru2it
Need help with a script im writing. Basically stuck on a grep command. root=s5 [~]# cat footer.php <!--ADDRTC--> <!--sldfdd--> code <!--footer--> foo bar <!--s5fJsfi--> <!--a08hhj--> <!--Footer--> <!--header--> root=s5 [~]# I ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2012
    Posts
    9

    Regex Help


    Need help with a script im writing. Basically stuck on a grep command.

    root=s5 [~]# cat footer.php
    <!--ADDRTC-->
    <!--sldfdd-->
    code
    <!--footer-->
    foo
    bar
    <!--s5fJsfi-->
    <!--a08hhj-->
    <!--Footer-->
    <!--header-->
    root=s5 [~]#

    I am trying to match all the lines below:
    <!--ADDRTC-->
    <!--sldfdd-->
    <!--a08hhj-->

    Pretty much all the lines that start with "<!--" followed by 6 characters ending with "-->" . The tricky part is those 6 characters cant be certain words such as header and footer. Not sure how to negate entire words like that. This is what I got so far:

    root=s5 [~]# egrep "<\!--[a-zA-Z0-9]{6}-->" footer.php
    <!--ADDRTC-->
    <!--sldfdd-->
    <!--footer-->
    <!--a08hhj-->
    <!--Footer-->
    <!--header-->
    root=s5 [~]#

    Still matching header and footer though and not sure how to stop that. I know I can pipe it to another grep -v command, but I really need to do this with 1 command in regex. Any ideas?

    Your help is appreciated.

  2. #2
    Just Joined!
    Join Date
    Apr 2013
    Posts
    2

    Wink

    grep -P "<\!--(?!=|((?i)foot|head)er)\w{6}-->"


    That will find all things:

    #grep -P "<\!--(?!=|((?i)foot|head)er)\w{6}-->"
    <!--ADDRTC-->
    <!--sldfdd-->
    <!--a08hhj-->
    samirj09 likes this.

Posting Permissions

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