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*

13
  • 1
    @EdMorton thanks so much! Edited accordingly. I did not know about that, that's a very good observation and information. Actually I do not know much about POSIX compliant, so I'm not sure if the code I use is good for portability or not. I appreciate these comments :). Commented Dec 8, 2022 at 15:07
  • 1
    You're welcome. FYI grep -R and tr --squeeze-repeats aren't portable (use -s instead of --squeeze-repeats, and IMHO no-one should ever use -R - use find to find files, not grep, the GNU guys really broke with UNIX philosophy by giving grep options to do the same things as find already does). Commented Dec 8, 2022 at 15:33
  • 1
    @EdMorton thanks again! I edited to include tr -s instead. About grep -R I will consider for future answers/uses (to avoid expand the script here, which is already some large to solve the problem). I never thought that grep -R was not portable , it surprises me. Commented Dec 8, 2022 at 16:11
  • 1
    Yeah -R is a poorly-thought-out GNUism. The UNIX philosphy is to have tools that do 1 thing and do it well working together when necessary. The tool to find files is named find, and the tool to g/re/p (the ed commands to Globally match a Regular Expression in a file and Print the result) is named grep. Giving grep the ability to also find files absolutely breaks that philosophy - why not give find, sed, awk, cut, tr and every other tool options to find files too? Why not also give grep options to replace text or sort it's output or translate characters? It's a nasty mistake. Commented Dec 8, 2022 at 16:15
  • 1
    No because in cases where POSIX doesn't define behavior GNU might do X while MacOS does Y. For example the meaning of print > "foo" 17 in awk is undefined by POSIX - GNU awk, with or without --posix, will treat it like print > ("foo" 17) but MacOS would treat it like (print > "foo") 17 and report it as a syntax error. All you CAN guarantee that --posix does is disable GNU extensions e.g. gensub() or multi-char RS because those things have a different, defined meaning to POSIX. Commented Dec 8, 2022 at 16:53