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.

1
  • 1
    Note that it doesn't work with mawk or busybox awk because of the syntax ambiguity of division / and the /ERE/ operator, and the special case of () being optional for length (still those implementations are not POSIX compliant in that case). Using length() or length($0) here instead of length would help for those. You could also do awk 'BEGIN{half = int(length(ARGV[1]) / 2); print substr(ARGV[1], 1, half) ORS substr(ARGV[1], half+1)}' abcdef which would save the pipe and extra process and make it work even if the string contains newline characters. Commented May 31, 2019 at 10:55