Skip to content
Advertisement

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’ve tried a variation of ways on that GREP

SED one liner to uncomment and replace first occurrence of a pattern

I have this settings.conf file in linux defined as follows: I would like to uncomment # second-setting = off of Section A only (first occurrence), and set the value to on. So far, I have this: cat settings.conf | sed ‘/^# second.*/ {s/^#//;s/off/on/}’ Any tips? Answer Is this what you had in mind? Or if your on osx with non-gnu

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 ‘output.temp’ ‘output’, output.temp.*.csv But this didn’t work… Any advice on how

.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.domain.com/a=a&v=b&id=c and needs to be http://sub.domain.com/a/b/c

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 without the extra commands: Edit: If you

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 there’s not 2x ( .*? lazily any amount of

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 file name?

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. What am I

Advertisement