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
  • Newlines matter in an awk script, /foo/ { bar } is not the same as /foo/<newline>{bar}. The former means "If foo then do bar" while the latter means "If foo then print the current line. Always do bar". So your script wouldn't do what you want given that. I think you're also misunderstanding what >> means in awk and assuming it means the same as it does in shell but it doesn't. Just change >> to > in your script and then you won't need to remove/truncate the output file before each run. Commented Aug 11 at 17:53
  • You could also get rid of most of the references to $1 and $0 and just do awk '/^#INV/ { sub(/^#/,"") ; out = $1".out" ; next } !/^#/ { print > out }' data but you should close() the output files as you finish writing to them to avoid a "too many open files" error from most awks given a large enough input file (or a dramatic slowdown from GNU awk). Commented Aug 11 at 17:58