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*

2
  • Thanks for the awk solution, I'm still a beginner with bash. What I actually don't understand is why while replacing the last grep command, without using any other trick like double quotes, filename is printed correctly. What I've seen till now is that redirection of stdout into a file always work, also with empty stdout. Commented Jun 13, 2018 at 10:16
  • @Shred Yes, any redirection with > creates the output file (or empties it if it exists) before the command is even started (if the output file is writable at all). Commented Jul 9, 2018 at 7:45