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.
- Prepare
- Linux Shell
- Grep Sed Awk
- 'Awk' - 4
- Discussions
'Awk' - 4
'Awk' - 4
Sort by
recency
|
80 Discussions
|
Please Login in order to post a comment
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
a longer solution, similar to the the use of the ternary operator:
awk '{if (NR%2) {ORS=";"} else {ORS="\n"}} {print}'
simply this works
try this people awk 'ORS=NR%2?";":"\n"'