Timeline for Bash: Show the contents of a text file, with every occurrence of a word highlighted
Current License: CC BY-SA 3.0
3 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 26, 2017 at 23:58 | comment | added | don_crissti |
@EliahKagan - will all due respect to goldilocks, you don't need to read the file twice, count the lines and use a non-standard option like -C just to be able to grep for fixed strings and print the non-matching lines too. It's much simpler than that.
|
|
| Jan 26, 2017 at 15:53 | comment | added | Eliah Kagan |
One advantage of this general method is that the -F option may be added; then word is interpreted as literal text to match rather than a regular expression. (The primary method given in my answer--and jacksonh's answer to the related question--don't readily support that enhancement.) An alternative to parsing the output of wc is to prevent it from ever knowing the filename by using input redirection instead of a path argument: $(wc -l < foo.txt)
|
|
| Jan 26, 2017 at 15:02 | history | answered | goldilocks | CC BY-SA 3.0 |