GREP Print Blank Lines For Non-Matches
Solution 1:
You can use
#!/bin/bash
s='This is very new
This is quite old
This is not so new'
sed -En 's/.*This(.*)new.*|.*/\1/p' <<< "$s"
See the online demo yielding
is very
is not so
Details:
-
E
- enables POSIX ERE regex syntax -
n
- suppresses default line output -
s/.*This(.*)new.*|.*/\1/
- finds any text,This
, any text (captured into Group 1,\1
, and then any text again, or the whole string (insed
, line), and replaces with Group 1 value. -
p
- prints the result of the substitution.
And this is what you need for your actual data:
sed -En 's/.*"user_ip":"([^"]*).*|.*/\1/p'
See this online demo. The [^"]*
matches zero or more chars other than a "
char.