We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The problem with the awk 'ORS=NR%2?";":"\n"' solution is it'll produce output that's separated by \ns which would be undesirable on a system where records are separated by \r\n, e.g. as is common in file created on Windows. awk 'ORS=NR%2?";":RS' solves that by using RS instead of "\n" in the script but then THAT would fail if the RS was the number 0 or similar. The robust, portable solution is awk '{ORS=(NR%2 ? ";" : RS)} 1' file
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
'Awk' - 4
You are viewing a single comment's thread. Return to all comments →
The problem with the
awk 'ORS=NR%2?";":"\n"'
solution is it'll produce output that's separated by\n
s which would be undesirable on a system where records are separated by\r\n
, e.g. as is common in file created on Windows.awk 'ORS=NR%2?";":RS'
solves that by usingRS
instead of"\n"
in the script but then THAT would fail if the RS was the number0
or similar. The robust, portable solution isawk '{ORS=(NR%2 ? ";" : RS)} 1' file