Skip to main content
Command corrected
Source Link
Prabhjot Singh
  • 2.4k
  • 1
  • 6
  • 20

Using awkAWK:

$ awk ''NR>1{if (NR>1)printf print"%s", a "," OFS;OFS} {a=$0}END {if (NR) print ""a}'

If only comma is needed without space and all records have only one fields, then datamash may be used.

$ datamash -W collapse 1 <file

Using awk:

$ awk '{if (NR>1) print a "," OFS; a=$0}END {if (NR) print ""}'

If only comma is needed without space and all records have only one fields, then datamash may be used.

$ datamash -W collapse 1 <file

Using AWK:

$ awk 'NR>1{printf "%s", a "," OFS} {a=$0}END {print a}'

If only comma is needed without space and all records have only one fields, then datamash may be used.

$ datamash -W collapse 1 <file
Command corrected
Source Link
Prabhjot Singh
  • 2.4k
  • 1
  • 6
  • 20

Using awk:

$ awk 'a{printf "%s", a ", "}{a=$0}END{print a}'

But the above command prints a line with an empty file. This can be modified to this:

$ awk '{if (aNR>1) printf "%s",print a "," OFS; a=$0}END {if (NR) print a""}'

If only comma is needed without space and all records have only one fields, then datamash may be used.

$ datamash -W collapse 1 <file

Using awk:

$ awk 'a{printf "%s", a ", "}{a=$0}END{print a}'

But the above command prints a line with an empty file. This can be modified to this:

$ awk '{if (a) printf "%s", a "," OFS; a=$0}END {if (NR) print a}'

If only comma is needed without space and all records have only one fields, then datamash may be used.

$ datamash -W collapse 1 <file

Using awk:

$ awk '{if (NR>1) print a "," OFS; a=$0}END {if (NR) print ""}'

If only comma is needed without space and all records have only one fields, then datamash may be used.

$ datamash -W collapse 1 <file
Command corrected
Source Link
Prabhjot Singh
  • 2.4k
  • 1
  • 6
  • 20

Using awk:

$ awk 'a{printf "%s", a ", "}{a=$0}END{print a}'

But the above command prints a line with an empty file. This can be modified to this:

$ awk '{if (a) printf "%s", a "," OFS; a=$0}END {if (NR) print a}'

If only comma is needed without space and all records have only one fields, then datamash may be used.

$ datamash -W collapse 1 <file

Using awk:

$ awk 'a{printf a ", "}{a=$0}END{print a}'

But the above command prints a line with an empty file. This can be modified to this:

$ awk '{if (a) printf a "," OFS; a=$0}END {if (NR) print a}'

If only comma is needed without space and all records have only one fields, then datamash may be used.

$ datamash -W collapse 1 <file

Using awk:

$ awk 'a{printf "%s", a ", "}{a=$0}END{print a}'

But the above command prints a line with an empty file. This can be modified to this:

$ awk '{if (a) printf "%s", a "," OFS; a=$0}END {if (NR) print a}'

If only comma is needed without space and all records have only one fields, then datamash may be used.

$ datamash -W collapse 1 <file
Command corrected
Source Link
Prabhjot Singh
  • 2.4k
  • 1
  • 6
  • 20
Loading
Source Link
Prabhjot Singh
  • 2.4k
  • 1
  • 6
  • 20
Loading