Skip to main content
added 5 characters in body
Source Link
steeldriver
  • 83.8k
  • 12
  • 124
  • 175

Awk programs consist of pattern {action} pairs, where {action} is performed if pattern evaluates TRUE. If pattern is omitted, it is assumed TRUE by default, while if {action} is omitted, the default action is {print}.

In

awk 'FS=","; OFS=","; {print $2, $3}' A.tsv

you have:

  1. pattern FS="," which assigns , as the value of FS, and as a side effect evaluates TRUE, triggering the default action {print}

  2. pattern OFS="," likewise assigns , to OFS, evaluates TRUE and triggers the default {print} action a second time

  3. action {print $2,$3} with no pattern, so the default TRUE is assumed and the action is triggered. However FS was not set to , until the first record had already been processed, so $2 and $3 are both empty (since awk used the default whitespace FS to parse the first record, assigning the whole record to $1). On subsequent records, it prints the expected comma-delimited values.

You probably intended to assign FS="," and OFS="," in an action before record processing begins - that's the function of a BEGIN block:

awk 'BEGIN{FS=","; OFS=","} {print $2, $3}' A.tsv

or

awk -F ',' ''BEGIN{OFS=FS} {print $2, $3}' A.tsv

Alternatively, you can pass variable assignments as arguments before the filename argument(s) (this is sometimes useful if you are processing multiple files and want to set different field separators for each)

awk '{print $2, $3}' FS="," OFS="," A.tsv

Awk programs consist of pattern {action} pairs, where {action} is performed if pattern evaluates TRUE. If pattern is omitted, it is assumed TRUE by default, while if {action} is omitted, the default action is {print}.

In

awk 'FS=","; OFS=","; {print $2, $3}' A.tsv

you have:

  1. pattern FS="," which assigns , as the value of FS, and as a side effect evaluates TRUE, triggering the default action {print}

  2. pattern OFS="," likewise assigns , to OFS, evaluates TRUE and triggers the default {print} action a second time

  3. action {print $2,$3} with no pattern, so the default TRUE is assumed and the action is triggered. However FS was not set to , until the first record had already been processed, so $2 and $3 are both empty (since awk used the default whitespace FS to parse the first record, assigning the whole record to $1). On subsequent records, it prints the expected comma-delimited values.

You probably intended to assign FS="," and OFS="," in an action before record processing begins - that's the function of a BEGIN block:

awk 'BEGIN{FS=","; OFS=","} {print $2, $3}' A.tsv

or

awk -F ',' '{OFS=FS} {print $2, $3}' A.tsv

Alternatively, you can pass variable assignments as arguments before the filename argument(s) (this is sometimes useful if you are processing multiple files and want to set different field separators for each)

awk '{print $2, $3}' FS="," OFS="," A.tsv

Awk programs consist of pattern {action} pairs, where {action} is performed if pattern evaluates TRUE. If pattern is omitted, it is assumed TRUE by default, while if {action} is omitted, the default action is {print}.

In

awk 'FS=","; OFS=","; {print $2, $3}' A.tsv

you have:

  1. pattern FS="," which assigns , as the value of FS, and as a side effect evaluates TRUE, triggering the default action {print}

  2. pattern OFS="," likewise assigns , to OFS, evaluates TRUE and triggers the default {print} action a second time

  3. action {print $2,$3} with no pattern, so the default TRUE is assumed and the action is triggered. However FS was not set to , until the first record had already been processed, so $2 and $3 are both empty (since awk used the default whitespace FS to parse the first record, assigning the whole record to $1). On subsequent records, it prints the expected comma-delimited values.

You probably intended to assign FS="," and OFS="," in an action before record processing begins - that's the function of a BEGIN block:

awk 'BEGIN{FS=","; OFS=","} {print $2, $3}' A.tsv

or

awk -F ',' 'BEGIN{OFS=FS} {print $2, $3}' A.tsv

Alternatively, you can pass variable assignments as arguments before the filename argument(s) (this is sometimes useful if you are processing multiple files and want to set different field separators for each)

awk '{print $2, $3}' FS="," OFS="," A.tsv
added 284 characters in body
Source Link
steeldriver
  • 83.8k
  • 12
  • 124
  • 175

Awk programs consist of pattern {action} pairs, where {action} is performed if pattern evaluates TRUE. If pattern is omitted, it is assumed TRUE by default, while if {action} is omitted, the default action is {print}.

In

awk 'FS=","; OFS=","; {print $2, $3}' A.tsv

you have:

  1. pattern FS="," which assigns , as the value of FS, and as a side effect evaluates TRUE, triggering the default action {print}

  2. pattern OFS="," likewise assigns , to OFS, evaluates TRUE and triggers the default {print} action a second time

  3. action {print $2,$3} with no pattern, so the default TRUE is assumed and the action is triggered. However FS was not set to , until the first record had already been processed, so $2 and $3 are both empty (since awk used the default whitespace FS to parse the first record, assigning the whole record to $1). On subsequent records, it prints the expected comma-delimited values.

You probably intended to assign FS="," and OFS="," in an action before record processing begins - that's the function of a BEGIN block:

awk 'BEGIN{FS=","; OFS=","} {print $2, $3}' A.tsv

The other casesor

awk -F ',' '{OFS=FS} {print $2, $3}' A.tsv

Alternatively, you can pass variable assignments as arguments before the filename argument(s) (this is sometimes useful if you are similar.processing multiple files and want to set different field separators for each)

awk '{print $2, $3}' FS="," OFS="," A.tsv

Awk programs consist of pattern {action} pairs, where {action} is performed if pattern evaluates TRUE. If pattern is omitted, it is assumed TRUE by default, while if {action} is omitted, the default action is {print}.

In

awk 'FS=","; OFS=","; {print $2, $3}' A.tsv

you have:

  1. pattern FS="," which assigns , as the value of FS, and as a side effect evaluates TRUE, triggering the default action {print}

  2. pattern OFS="," likewise assigns , to OFS, evaluates TRUE and triggers the default {print} action a second time

  3. action {print $2,$3} with no pattern, so the default TRUE is assumed and the action is triggered. However FS was not set to , until the first record had already been processed, so $2 and $3 are both empty (since awk used the default whitespace FS to parse the first record, assigning the whole record to $1). On subsequent records, it prints the expected comma-delimited values.

You probably intended to assign FS="," and OFS="," in an action before record processing begins - that's the function of a BEGIN block:

awk 'BEGIN{FS=","; OFS=","} {print $2, $3}' A.tsv

The other cases are similar.

Awk programs consist of pattern {action} pairs, where {action} is performed if pattern evaluates TRUE. If pattern is omitted, it is assumed TRUE by default, while if {action} is omitted, the default action is {print}.

In

awk 'FS=","; OFS=","; {print $2, $3}' A.tsv

you have:

  1. pattern FS="," which assigns , as the value of FS, and as a side effect evaluates TRUE, triggering the default action {print}

  2. pattern OFS="," likewise assigns , to OFS, evaluates TRUE and triggers the default {print} action a second time

  3. action {print $2,$3} with no pattern, so the default TRUE is assumed and the action is triggered. However FS was not set to , until the first record had already been processed, so $2 and $3 are both empty (since awk used the default whitespace FS to parse the first record, assigning the whole record to $1). On subsequent records, it prints the expected comma-delimited values.

You probably intended to assign FS="," and OFS="," in an action before record processing begins - that's the function of a BEGIN block:

awk 'BEGIN{FS=","; OFS=","} {print $2, $3}' A.tsv

or

awk -F ',' '{OFS=FS} {print $2, $3}' A.tsv

Alternatively, you can pass variable assignments as arguments before the filename argument(s) (this is sometimes useful if you are processing multiple files and want to set different field separators for each)

awk '{print $2, $3}' FS="," OFS="," A.tsv
deleted 34 characters in body
Source Link
steeldriver
  • 83.8k
  • 12
  • 124
  • 175

Awk programs consist of pattern {action} pairs, where {action} is performed if pattern evaluates TRUE. If pattern is omitted, it is assumed TRUE by default, while if {action} is omitted, the default action is {print}.

In

awk 'FS=","; OFS=","; {print $2, $3}' A.tsv

you have:

  1. pattern FS="," which assigns , as the value of FS, and as a side effect evaluates TRUE, causingtriggering the default action {print} to be taken

  2. pattern OFS="," likewise assigns , to OFS, evaluates TRUE and performstriggers the default {print} action a second time

  3. action {print $2,$3} with no pattern, so the default TRUE is assumed and the action is performedtriggered. However FS was not set to , until the first record had already been processed, so $2 and $3 are both empty (since awk used the default whitespace FS to parse the first record, assigning the whole record to $1). On subsequent records, it prints the expected comma-delimited values.

You probably intended to assign FS="," and OFS="," in an action (rather than a pattern), before record processing begins - that's the function of a BEGIN block:

awk 'BEGIN{FS=","; OFS=","} {print $2, $3}' A.tsv

The other cases are similar.

Awk programs consist of pattern {action} pairs, where {action} is performed if pattern evaluates TRUE. If pattern is omitted, it is assumed TRUE by default, while if {action} is omitted, the default action is {print}.

In

awk 'FS=","; OFS=","; {print $2, $3}' A.tsv

you have:

  1. pattern FS="," which assigns , as the value of FS, and as a side effect evaluates TRUE, causing the default action {print} to be taken

  2. pattern OFS="," likewise assigns , to OFS, evaluates TRUE and performs the default {print} action a second time

  3. action {print $2,$3} with no pattern, so the default TRUE is assumed and the action is performed. However FS was not set to , until the first record had already been processed, so $2 and $3 are both empty (since awk used the default whitespace FS to parse the first record, assigning the whole record to $1). On subsequent records, it prints the expected comma-delimited values.

You probably intended to assign FS="," and OFS="," in an action (rather than a pattern), before record processing begins - that's the function of a BEGIN block:

awk 'BEGIN{FS=","; OFS=","} {print $2, $3}' A.tsv

The other cases are similar.

Awk programs consist of pattern {action} pairs, where {action} is performed if pattern evaluates TRUE. If pattern is omitted, it is assumed TRUE by default, while if {action} is omitted, the default action is {print}.

In

awk 'FS=","; OFS=","; {print $2, $3}' A.tsv

you have:

  1. pattern FS="," which assigns , as the value of FS, and as a side effect evaluates TRUE, triggering the default action {print}

  2. pattern OFS="," likewise assigns , to OFS, evaluates TRUE and triggers the default {print} action a second time

  3. action {print $2,$3} with no pattern, so the default TRUE is assumed and the action is triggered. However FS was not set to , until the first record had already been processed, so $2 and $3 are both empty (since awk used the default whitespace FS to parse the first record, assigning the whole record to $1). On subsequent records, it prints the expected comma-delimited values.

You probably intended to assign FS="," and OFS="," in an action before record processing begins - that's the function of a BEGIN block:

awk 'BEGIN{FS=","; OFS=","} {print $2, $3}' A.tsv

The other cases are similar.

added 231 characters in body
Source Link
steeldriver
  • 83.8k
  • 12
  • 124
  • 175
Loading
Source Link
steeldriver
  • 83.8k
  • 12
  • 124
  • 175
Loading