Skip to main content
added 129 characters in body
Source Link
grebneke
  • 4.8k
  • 27
  • 20

This should work:

linearray=($(awk -F: '1''{$1=$1} 1' <<<"${smryline}"))
echo ${linearray[2]}
# output: 27

Explanation: awk -F: splits input on :. awk by default separates modified output with a space, so you can construct an bash array directly with the output from awk. Note modified output, hence the no-op call to $1=$1, else the data would just come out in the original form.

But given your example, why not extract the third column with awk -F: and loop the output:

awk -F: '{print $3}' "$smryfile" | while read varX; do
    echo $varX
done

This should work:

linearray=($(awk -F: '1' <<<"${smryline}"))
echo ${linearray[2]}

Explanation: awk -F: splits input on :. awk by default separates output with a space, so you can construct an bash array directly with the output from awk.

But given your example, why not extract the third column with awk -F: and loop the output:

awk -F: '{print $3}' "$smryfile" | while read varX; do
    echo $varX
done

This should work:

linearray=($(awk -F: '{$1=$1} 1' <<<"${smryline}"))
echo ${linearray[2]}
# output: 27

Explanation: awk -F: splits input on :. awk by default separates modified output with a space, so you can construct an bash array directly with the output from awk. Note modified output, hence the no-op call to $1=$1, else the data would just come out in the original form.

But given your example, why not extract the third column with awk -F: and loop the output:

awk -F: '{print $3}' "$smryfile" | while read varX; do
    echo $varX
done
deleted 20 characters in body
Source Link
grebneke
  • 4.8k
  • 27
  • 20

This should work:

linearray=($(awk -F: '1' <<<"${smryline}"))
echo ${linearray[2]}

Explanation: awk -F: splits input on :. awk by default separates output with a space, so you can construct an bash array directly with the output from awk.

But given your example, couldn't you justwhy not extract the desired third column with awk -F: and the loop over that?the output:

awk -F: '{print $3}' "$smryfile" | while read varX; do
    echo $varX
done

This should work:

linearray=($(awk -F: '1' <<<"${smryline}"))
echo ${linearray[2]}

Explanation: awk -F: splits input on :. awk by default separates output with a space, so you can construct an bash array directly with the output from awk.

But given your example, couldn't you just extract the desired third column with awk and the loop over that?

awk -F: '{print $3}' "$smryfile" | while read varX; do
    echo $varX
done

This should work:

linearray=($(awk -F: '1' <<<"${smryline}"))
echo ${linearray[2]}

Explanation: awk -F: splits input on :. awk by default separates output with a space, so you can construct an bash array directly with the output from awk.

But given your example, why not extract the third column with awk -F: and loop the output:

awk -F: '{print $3}' "$smryfile" | while read varX; do
    echo $varX
done
Source Link
grebneke
  • 4.8k
  • 27
  • 20

This should work:

linearray=($(awk -F: '1' <<<"${smryline}"))
echo ${linearray[2]}

Explanation: awk -F: splits input on :. awk by default separates output with a space, so you can construct an bash array directly with the output from awk.

But given your example, couldn't you just extract the desired third column with awk and the loop over that?

awk -F: '{print $3}' "$smryfile" | while read varX; do
    echo $varX
done