I am trying to replace a string in the config file. I would like to run something like this: OS (docker image php:8.1-apache-buster) Debian GNU/Linux 10 (buster) sed (GNU sed) 4.7 Packaged by Debian Possible inputs: Example output (any user given value): Example cmd: Joining regex with strings does not work here. It works when I run string replace without
Tag: regex
Bash match on any lines that have any number of whitespace up to #
I need to clean up a config file before a source it. I need to remove any lines that have Start with # Any number of white space then a # blank lines Remove (and including) # and everything after it if line starts with a string. Example config: I have this right now The problem is line 2, #
The sed command is not working with regex
I’m parsing the output of a HTTP GET request with sed to retrieve the contents of a given html tag. The result of that request is like this: “<!DOCTYPE html><html><body><h1>Hello!</h1><p>v1.0.4-b</p></body></html>” And I want to retrieve the version number inside the p element. However, sed seems to have a bug in regex parsing. When I use: sed ‘s/.*<p>//’ It correctly replaces
Regular expression operator {} in linux bash
I’m having some problems with the {} operator. In the following examples, I’m trying to find the rows with 1, 2, and 2 or more occurrences of the word mint, but I get a response only if I search for 1 occurrence of mint, even though there are more than 1 per row. The input I am processing is a
reading and analyzing a text file with bash script
I want to read a log file and want to extract 5-6 number digit that is written right next after the keyword “salary”. And then want to analyze if the salary is above 2000. If there is even one above 2000, it is a MNC otherwise unknown. After writing the salary, the line ends mostly but sometimes there is an
How to apply regex to specific column in awk
This will colorize the output of ls -lhAXF How to apply the color to specific type of item using regex, for example i want the folder to be green, the .config folder red, the regular file blue or something like that. folder – match $9 column containing ‘/’ in the end of word hidden folder – match $9 column containing
not sure what’s the problem with this “regex” in the “grep” shell command
This was my attempt: I’m on hackerRank. I have this file that is delivered to my stdin. I need as a result lines that contains : Answer In a POSIX BRE pattern, when you use a “shorthand character class” like s, w, even in GNU grep, these escape sequences are treated as separate chars, a backslash and a letter. [D]{1,}
How to use regex to match both filename and file content in Linux? [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 1 year ago. Improve this question I want to find files that contain the word ‘virus’ but not ‘antivirus’ (case insensitive) in both their filename and their content. Thanks for your
Regex match with capturing group excluding specific characters and looking for the last occurrence based on later characters
I apologize beforehand for the jumbled mess that is the title but that’s the shortest way I could think to describe what I’m trying to do. I’m reading a file that has multiple lines of text that I’m looping through and I’m trying to use regex to get a substring from each line. These lines will start with the word
How to replace a hash pattern inside file and directory names (Linux)
I’ve just backed up the notes I have in Notion, and they use hashcodes in the notes names to make them unique apparently. For example, this is might be a note-folder with some notes: (Sometimes there’s also a .csv file for tables) I was trying to use a regex like [a-z0-9]{32} to replace the pattern, but was having difficulty making