Skip to main content
added 145 characters in body
Source Link
Barmar
  • 10.6k
  • 1
  • 22
  • 29

DL_OPS is a single value, not an array. When you use array indexing with a non-array variable, index 0 is the value, other indexes are empty.

If you just wrap () around the call to awk, it will split the output at any whitespacethe space characters, so each word will be a separate array element. You need to split it just at newlines, which you can do by setting IFS.

You should also disable filename wildcard expansion, in case the file contains wildcards that happen to match filenames.

set -o noglob
IFS=$'\n' DL_OPS=($(awk -F "|" 'NR>1 {print $4}' input_file.txt))

DL_OPS is a single value, not an array. When you use array indexing with a non-array variable, index 0 is the value, other indexes are empty.

If you just wrap () around the call to awk, it will split the output at any whitespace, so each word will be a separate array element. You need to split it just at newlines, which you can do by setting IFS.

IFS=$'\n' DL_OPS=($(awk -F "|" 'NR>1 {print $4}' input_file.txt))

DL_OPS is a single value, not an array. When you use array indexing with a non-array variable, index 0 is the value, other indexes are empty.

If you just wrap () around the call to awk, it will split the output at the space characters, so each word will be a separate array element. You need to split it just at newlines, which you can do by setting IFS.

You should also disable filename wildcard expansion, in case the file contains wildcards that happen to match filenames.

set -o noglob
IFS=$'\n' DL_OPS=($(awk -F "|" 'NR>1 {print $4}' input_file.txt))
Source Link
Barmar
  • 10.6k
  • 1
  • 22
  • 29

DL_OPS is a single value, not an array. When you use array indexing with a non-array variable, index 0 is the value, other indexes are empty.

If you just wrap () around the call to awk, it will split the output at any whitespace, so each word will be a separate array element. You need to split it just at newlines, which you can do by setting IFS.

IFS=$'\n' DL_OPS=($(awk -F "|" 'NR>1 {print $4}' input_file.txt))