I have a file/output containing this : I would like to extract all public subnet id and print them without, and white space. I used this regex And the output is : But I would like to get this instead: In fact I told sed to replace spaces and newlines with nothing (s/[[:space:]]//g) and then it also replace the first
Tag: regex
How to add a word at the beginning of each line BUT not when a # is present
Given a file with many ENV variables. Example: DEV.env I know the command sed “s/^/export /g” will add export at the beginning of each line. But I don’t want to do this when the first character is “#”. How can I do with sed? Answer Something like this: Alternatives:
Align/pad some content in these strings with regex in javascript
I have these strings: and i want to convert them to this: Want to do it with Regular Expressions in Javascript. NOTE 1: The goal is to align the data in the “fifth, sixth and seven column” from right to left. The fifth column has from 1 to 3 digits. The sixth column always has 1 digit, a dot and
Grep Pattern matching- underline
I’ve not been able to find anything online to help so hoping someone may have an idea. What does an underline in an expression mean when using grep? For example: [_a-zA-Z0-9] Could someone help to explain the purpose here? Answer The grep command uses a regular expression as it is also described in the manpage of grep: A regular expression
Is it possible to pass regex strings as args to a Python CLI tool using argparse?
I’m writing a script to search a logfile for a given python regex pattern. Setting aside the fact that this would be much easier to do using a simple Bash script, can it be done in Python? Here’s what I’ve run into: Assumptions: I’m trying to analyze the file /var/log/auth.log (for the sake of simplicity, I’m omitting the ability to
How to use sed to delete lines not containing pattern
I have a file as below: I need to delete all lines except the first line, which means that lines should not be deleted if it contains Thumb[any characters except /].jpg. I try to use sed to do this but I don’t know how to write the regex. I’ve tried like this: sed -i -e ‘.*Thumb^(/).jpg!d’ file but it doesn’t
Use awk to match a word, then find the first occurrence of another word
I am trying to find a way to re-search for another matching word after I already had a match. I am specifically trying to get the brightness value of one of my monitors. For example a part of the output of my xrandr –verbose is the following: I want to look for the word connected and then get the first
Regex Pattern matching refinement
I have a json that is returned to a variable, I’m trying to only grab values of from the json. I’m only limited to grep, sed, and awk returns me the result and honestly the only part I want is Answer With jq, you could use ‘.results[0] | .path’ filter. You may play around with this tool online here. However,
Sed: select first part of price
Seems that my sed command is not working. I am trying to select the 2 in $2.99. However, no matter how I seem to type the regex, it will only give the .99 I want to select everything (every number) that is not the dollar sign up to the period. Any suggestions? echo “$2.99” | sed -e ‘s:^([^\$]*).:the price is
Pcregrep include file extension bug
I’m using pcregrep to search for a multiline pattern, and I only want pcregrep to search through files with specific file extensions, i.e. pcregrep -Mrl –include=*.sv -e ‘<my_multi-line_pattern>’ /path/to/search However, this throws an error: pcregrep: Error in ‘include’ regex at offset 0: nothing to repeat. I’ve tried escaping & double-escaping the * to no avail. This syntax seems to work