{"id":5571,"date":"2013-06-07T14:10:00","date_gmt":"2013-06-07T14:10:00","guid":{"rendered":""},"modified":"2026-04-18T22:45:32","modified_gmt":"2026-04-18T22:45:32","slug":"using-notepad-and-regex-to-search-and-append-text","status":"publish","type":"post","link":"https:\/\/hellem.org\/wblog\/?p=5571","title":{"rendered":"Using Notepad++ and regex to search and append text"},"content":{"rendered":"<p>Needed to search an access.log file from Apache where each line started with an ip-address. Due to a limitation in AWstats, see <a href=\"http:\/\/www.bityard.org\/blog\/2012\/07\/21\/apache_awstats_x-forwarded-for\">bityard.org\/&#8230;\/apache_awstats_x-forwarded-for<\/a> I did have to update the current log file (and later update httpd.conf to get rid of difference in # of fields)<\/p>\n<p>Anyhow, in order to get a workaround I needed to add the missing hyphen &#8216;-&#8216; for all requests that does not use the load balancer. Pretty simple, many blog posts on how to do it, e.g <a href=\"http:\/\/stackoverflow.com\/questions\/283608\/using-regex-to-prefix-and-append-in-notepad\">stackoverflow.com\/&#8230;\/using-regex-to-prefix-and-append-in-notepad<\/a>. To append, use \\1 (and \\2 etc if needed). My regex expression was<br \/>\n<!-- codeblock lang=\"\" line=\"1\" --><\/p>\n<pre><code>^(?:[0-9]{1,3}\\.){3}[0-9]{1,3}\\s-<\/code><\/pre>\n<p><!-- \/codeblock --> Confirmed by using http:\/\/gskinner.com\/RegExr\/.<br \/>\nProblem was that the &#8216;\\1&#8217; did not work&#8230;until I <a href=\"http:\/\/en.wikipedia.org\/wiki\/RTFM\">RTFM<\/a>. I needed to add a parenthesis to create a collection so that Notepad++ (Or more correct the Regex-engine knew what I refer to when using &#8216;\\n&#8217;).<br \/>\n<!-- codeblock lang=\"\" line=\"1\" --><\/p>\n<pre><code>(^(?:[0-9]{1,3}\\.){3}[0-9]{1,3}\\s-)<\/code><\/pre>\n<p><!-- \/codeblock --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Needed to search an access.log file from Apache where each line started with an ip-address. Due to a limitation in AWstats, see bityard.org\/&#8230;\/apache_awstats_x-forwarded-for I did have to update the current log file (and later update httpd.conf to get rid of difference in # of fields) Anyhow, in order to get a workaround I needed to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47],"tags":[],"class_list":["post-5571","post","type-post","status-publish","format-standard","hentry","category-work-geek"],"_links":{"self":[{"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/posts\/5571","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5571"}],"version-history":[{"count":1,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/posts\/5571\/revisions"}],"predecessor-version":[{"id":12053,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/posts\/5571\/revisions\/12053"}],"wp:attachment":[{"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}