I have a file.xml so composed: I need to extract the following information: mayor_and_minor_release_number –> 1.0 patch_number –> 13 suffix –> -alpha I’ve thought the cleanest way to achieve that is by mean of a regex with grep command: I’ve checked with regex101 the correctness of this regex and actually it seems to properly capture the 3 fields I’m looking
Tag: regex
Skipping a part of a line using sed
I have a file with content like so – @1: 00001109 Each line is of the same format. I want the final output to be @1: 00 00 11 09. I used command in sed to introduce a space every 2 characters – sed ‘s/.{2}/& /g’. But that will give me spaces in the part before the colon too which
Searching two patterns in files that appear in the same file but may not appear on the same line
From a directory, I need to find all files that contain a decimal numbers say 42.7 AND the keyword “foo” or “goo”. How could I achieve that? Suppose I have a directory with three files The search command should give file1.txt and file3.txt. What is a search command to achieve this? i searched for the solutions but all I could
Remove ” and n using sed
How to replace the below text using sed or in any other method. I need to replace the above to be like Answer A or . needs to be escaped in regex pattern. You may use this sed: You may consider this awk to remove ” and n characters anywhere in the file:
Bash regex for same sender and receiver with backreference
I try to make a regex (important that ist a regex because i need it for fail2ban) to match when the receiver and the sender are the same person: What am I doing wrong ? Answer You might use a pattern to match the format of the string between the brackets with a backreference to that capture. Explanation from Match
how to edit a line having IPv4 address using sed command
I need to modify an ntp configuration file by adding some options to the line containing Ip addresses. I have been trying it for so long using sed command, but no able to modify the line unless i don’t know the IP addresses. Let say, i have few lines as, server 172.0.0.1 server 10.0.0.1 I need to add iburst option
How do i extract some particular words from each line?
The text file has many lines of these sort , i want to extract the words after /videos till .mp4 and the very last number ( shown in bold ) and output each filtered line in a separate file Lets say for example the text file content is .. The output should be Answer You may try the below regex:
list tables from mysql dump file with sed
I have situation where I need to extract tables list from mysql dump file. I tried that with sed but got this error what did I miss in my regexp? Answer Since you are using Linux, and you need to get all strings inside the first backticks after DROP TABLE, I’d suggest using grep with a PCRE regex like See
Linux read file line by line, print regex and print everything between two patterns
I made this script: Output of hc_connesse is: I’m not able to print SE401 from hc_connesse. The query is made on 45 different server and without putting the SE04 before the table will be impossible to understand which data are from where. Tried another For cycle inserting another awk before the other. Tried putting the two awk on one line.
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