Skip to main content
variable field selection.
Source Link
Archemar
  • 32.3k
  • 18
  • 75
  • 107

You’re specifying the output field separator, not the input field separator; use this instead:

varioutput=$(awk -F, '{print $j}' data/damper.test_temp1.csv) 

(or set FS instead of OFS).

I’m also assuming that j is a placeholder above, and that you’re replacing it statically with the appropriate value (for example, print $4).


To use another variable from script, you must pass it to awk

e.g. for RANK variable in shell

varioutput=$(awk -F, -v j=$RANK '{print $j}' data/damper.test_temp1.csv) 

Generally speaking, if you start using AWK for small pieces of a script as in this example, it’s better to use AWK for more of the script.

You’re specifying the output field separator, not the input field separator; use this instead:

varioutput=$(awk -F, '{print $j}' data/damper.test_temp1.csv) 

(or set FS instead of OFS).

I’m also assuming that j is a placeholder above, and that you’re replacing it statically with the appropriate value (for example, print $4).

Generally speaking, if you start using AWK for small pieces of a script as in this example, it’s better to use AWK for more of the script.

You’re specifying the output field separator, not the input field separator; use this instead:

varioutput=$(awk -F, '{print $j}' data/damper.test_temp1.csv) 

(or set FS instead of OFS).

I’m also assuming that j is a placeholder above, and that you’re replacing it statically with the appropriate value (for example, print $4).


To use another variable from script, you must pass it to awk

e.g. for RANK variable in shell

varioutput=$(awk -F, -v j=$RANK '{print $j}' data/damper.test_temp1.csv) 

Generally speaking, if you start using AWK for small pieces of a script as in this example, it’s better to use AWK for more of the script.

Address the general issue, and clarify "j".
Source Link
Stephen Kitt
  • 482.8k
  • 60
  • 1.2k
  • 1.4k

You’re specifying the output field separator, not the input field separatorseparator; use this instead:

varioutput=$(awk -F, '{print $j}' data/damper.test_temp1.csv) 

(or set FS instead of OFS).

I’m also assuming that j is a placeholder above, and that you’re replacing it statically with the appropriate value (for example, print $4).

Generally speaking, if you start using AWK for small pieces of a script as in this example, it’s better to use AWK for more of the script.

You’re specifying the output field separator, not the input field separator:

varioutput=$(awk -F, '{print $j}' data/damper.test_temp1.csv) 

(or set FS instead of OFS).

You’re specifying the output field separator, not the input field separator; use this instead:

varioutput=$(awk -F, '{print $j}' data/damper.test_temp1.csv) 

(or set FS instead of OFS).

I’m also assuming that j is a placeholder above, and that you’re replacing it statically with the appropriate value (for example, print $4).

Generally speaking, if you start using AWK for small pieces of a script as in this example, it’s better to use AWK for more of the script.

Source Link
Stephen Kitt
  • 482.8k
  • 60
  • 1.2k
  • 1.4k

You’re specifying the output field separator, not the input field separator:

varioutput=$(awk -F, '{print $j}' data/damper.test_temp1.csv) 

(or set FS instead of OFS).