Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • Very very nifty ! And thanks for the wiki.wooledge.org "eval" link. Commented Sep 24, 2018 at 10:29
  • That's some crazy bash code golf - love it! Commented Sep 24, 2018 at 22:53
  • Maybe grep -F "$(eval eval printf "'\"%s\n\"'" "'\${a:'{0..$((${#a}-$1))}':$1}'")" data.log. No <(…), no "fence" `\\\`, and "fixed strings" (no pipe -> faster) used. Commented Sep 26, 2018 at 3:22
  • @Isaac, Thanks! The -F is better, since the substring list is never going to be too large. See revised answer. The advantage of changing the quoting seems less obvious. Using a hard coded file name... my earlier versions of this, (before it was posted), included the file name, but leaving it out saved space, and was more versatile. Since it's a function, we could just make the 2nd argument the filename, but STDIN seems simpler. Commented Sep 26, 2018 at 3:58