Skip to content
Advertisement

Tag: regex

Extract a block from file between two lines

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

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

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

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

Advertisement