Skip to content
Advertisement

Tag: regex

Delete logs that ended with date format

I created the following cli in order to delete the logs with date format that oldest then 500 min date format is: the cli that should removed the logs as we can see the logs still exists where I am wrong? Answer Your regex does not match the files. Change ‘.*.log.[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{2,10}$’ for ‘.*.log.[0-9]{4}-[0-9]{2}-[0-9]{2,10}$’ since there’s no third hyphen (nor fourth

How can I specify a regex in a zgrep/zcat command?

I want to find in a list of words, every words with a least 3 times the same letter in it. To achieve that I did .*(w).*1.*1.*1.* and you can test it here http://www.regexplanet.com/advanced/java/index.html but I don’t know how to put it in my zgrep command. How can I insert this regex in a zgrep command ? Answer A couple

How to use zgrep and regular expression?

I’m trying to do some research in a .gz file so I found out I should use zcat / zgrep now after a bit of research I can’t figure out how to use a regex with zgrep I tried to do it like this zgrep ‘[sS]{10,}’ a.gz but nothing comes out even if there are string of minimum 10 characters

capturing words between double quotes in awk

I’m trying to print the name of my Linux distribution. The output of cat /etc/os-release for my distro is: Now I want to grab the Arch Linux from the second line. I used this command: But this prints PRETTY_NAME=”Arch How can I grab the words (including space) from this line? Answer Setting the field delimiter to double quotes -F'”‘ to

Remove part of a string by using bash

I have the path /home/bamboo/bamboo-agent-home/xml-data/build-dir/NG-VOSGQL239-JOB1 and would like to get just /home/bamboo/bamboo-agent-home/xml-data/build-dir/ How can I delete the last part of the path if it can be with different lengths by using Bash? Answer Using bash regex =~:

python filter lines matching keyworks

I have working python script producing following output. Script output Now i want want any line starting with stream in output so i am using following logic but its not working. Answer Your data is a massive string instead of a list of strings as you expected. Also it’s easier to use str.startswith instead of regex (less resource hungry). Simply

Why isn’t this sed command working for the regex?

I want to remove the multi-line comments in Java using sed command. The regex is working if we use character ranges like a-zA-Z0-9 etc. but not in case of word character like wS. Test-File content: Command used : Expected results: Actual results: Answer You can use grep with a regex (-E) and inverted matches (-v), i.e.: Output:

How to use back-reference of sed replacement command correctly considering a special Regular Expression

I am learning the sed s/regexp/replacement/ command on linux. There are some numbers from phone.txt I’d like to use the regular expression (which I have tested on https://www.freeformatter.com/regex-tester.html) to match numbers which begin with (555). And then I want the output of these three parts of these matched number as: (an example for number (555)555-1212) I tried the following command:

Advertisement