Timeline for Convince grep to output all lines, not just those with matches
Current License: CC BY-SA 3.0
21 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Feb 5, 2022 at 13:04 | comment | added | Dean P | Totally power hack | |
Dec 21, 2020 at 3:15 | comment | added | Lynch |
@OlivierDulac the -- are not something you would want to remove. It is something to make your script more robust. You don't have to fight the double dash. What if "${@:2}" == --something-funny ?
|
|
Dec 19, 2020 at 0:18 | comment | added | Olivier Dulac |
@Lynch: reverse the order of arguments to grep to not need the -- : highlight() { grep --color -E "^|$1" "${@:2}"; }
|
|
May 9, 2020 at 21:27 | comment | added | Tim |
You can also use the shorter version highlight () { grep --color -E "$1|$" ; } if you only want to pipe into it, like helm deploy | highlight configured for example.
|
|
Jan 2, 2020 at 2:36 | comment | added | nhed |
you don't need the dollar after the OR - grep --color -E "test|" yourfile ... that might help cuz now you don't need to escape in the double-quote string
|
|
Aug 28, 2017 at 19:42 | comment | added | Jack O'Connor | I find the same result as @Lynch. Does the answer as written work for anyone? | |
Feb 20, 2017 at 15:35 | history | edited | user147505 | CC BY-SA 3.0 |
added 2 characters in body
|
Mar 13, 2016 at 5:08 | comment | added | Lynch |
I came up with this ${@:2} with bash because you dont want the first argument to be repeated in the list files to check. highlight() { grep --color -E -- "$1|\$" "${@:2}"; } . Note the -- also to signigy that arguments with dash are done, so if you search a pattern line -something its still working.
|
|
S Jan 5, 2016 at 19:11 | history | edited | Jeff Schaller♦ | CC BY-SA 3.0 |
Added function example (from the comments)
|
S Jan 5, 2016 at 19:11 | history | suggested | David Ferenczy Rogožan | CC BY-SA 3.0 |
Added function example.
|
Jan 5, 2016 at 18:56 | review | Suggested edits | |||
S Jan 5, 2016 at 19:11 | |||||
Nov 22, 2014 at 21:40 | comment | added | Nate |
What do you mean when you say you're matching against the "$ pattern"? Doesn't the $ character mean end of line?
|
|
Aug 29, 2013 at 2:28 | comment | added | Drav Sloan |
I have my LESS environment set to (amongst other flags) -r , so I've modified the alias to grep --color=always ... so long files can be piped to less and still have the highlight :)
|
|
May 4, 2013 at 20:30 | history | edited | Anthon | CC BY-SA 3.0 |
added 6 characters in body
|
Nov 17, 2011 at 11:48 | comment | added | Chris Down |
@MikeDeSimone - But that will also have "$1" in the files. Use highlight () { grep --color -E "$1|$" "${@:1}" }
|
|
Jul 24, 2011 at 5:34 | comment | added | Mike DeSimone |
Better could be: highlight () { grep --color -E "$1|$" "$@" } which allows files with whitespace in their names and multiple files.
|
|
Mar 17, 2011 at 20:04 | comment | added | Dennis Williamson |
@StefanLasiewski: "$2" should also be quoted.
|
|
Oct 14, 2010 at 3:48 | comment | added | Stefan Lasiewski |
And as a function: highlight () { grep --color -E "$1|$" $2 ; } . Usage: highlight test yourfile
|
|
Aug 12, 2010 at 3:36 | vote | accept | Michael Mrozek | ||
Aug 12, 2010 at 3:09 | comment | added | gvkv | That's freaking awesome! | |
Aug 12, 2010 at 2:52 | history | answered | jacksonh | CC BY-SA 2.5 |