Skip to content

Tag: regex

Grep regexp for matching ip addresses in a file

I’m trying to search a file “Sessions” that contains IP addresses (among other useless junk). My Grep is failing to match, even though REGEXR is matching perfectly all the IPs perfectly … so I know the REGEX is correct … but when I GREP for this same pattern, not is returned. I&#…

linux rename multiple files using rename

I have a bunch of files (several thousand) called: output.temp.1.csv output.temp.2.csv output.temp.3.csv etc. I would like them all to be renamed but having the .temp removed output.1.csv output.2.csv output.3.csv etc. I think rename is what i need but not sure how to go about doing it I tried: rename ‘…

.htaccess RewriteRule keeping URL structure

My current rewrite rule: The result above works great so I can format the URL like domain.com/a/b/c I would like to add in a domain switch as well so the results I want is sub.domain.com/a/b/c when you access it using domain.com/a/b/c Currently here is what I have tried But the result of this is http://sub.do…

How to grep a particular pattern

I am trying to get a particular pattern, but i get the result for all possible solutions I did try all the solutions available here How do I get only the PID: 467? Answer If your goal is to grep only for “lubuntu”, not “lubuntu-somethingelse”, then you can add a space afterwards: Or wi…

Regext to match only ONE occurance of a pattern

How to write a regex that says that given pattern is present ONLY once? for e.g.. if am searching for pattern ‘file’, Answer You could use a negative lookahead: Test at regex101 You may apply the above regex in grep. The negative lookahead assertion at ^ start (?!(?:.*?file){2}) looks ahead, if th…

grep first n rows, return file name only

I can do the following to search for what I need and return the file name: grep -l “mysearchstring” ./*.xml However the files I am searching are huge so this takes forever. The string I am searching will appear in the first 200 rows so how can I search only the first 200 rows and still return the …

How to use awk regex sort by query string value?

I have a log file with example row: The 7th column of each row looks like this: Output is arranged according to the number of lines in decreasing order containing unique values of t. Desired OUTPUT: I am using awk but it is not giving desired output: It outputs all columns after 7th which is not required. Wha…