[Solved] Perl To Parse Whitespace Separated Columns


Easy as a one-liner:

perl -lane 'print join ",", map qq("$_"), @F[0, 1]'
  • -l handles newlines in print
  • -n reads the input line by line
  • -a splits each line on whitespace into the @F array
  • @F[0, 1] is an array slice, it extracts the first two elements of the @F array
  • map wraps each element in double quotes
  • join inserts the comma in between

5

solved Perl To Parse Whitespace Separated Columns