How to handle one value below the other

Hi,

I, have an output with 3 different values each below the other like:
[root]# echo $bla
123
345
234

Each value is in one line and for the further processing I need every single value.
For example is there a way to grep line 2, like:
[root]# echo $bla | grep --line 2
345

:slight_smile:

Thank you in advance
2retti

echo $bla | awk 'BEGIN {tot=0} "totalvcpu" {tot=tot+$1} END {print tot}'

Just a example but it shows how to handle individual value.

You need to learn little advance in awk.

Thats not what I need. I want to work with each line within a for-loop. There must be a way to print out a specific line by the number of the line.

awk 'NR==2{print $0}' filename

This will display 2nd line of file named filename

1 Like

Thank you!!!! Thats exactly what need!!!

Another way of doing the same thing (compact one)

awk 'NR==2' filename

Another way of doing the same thing (complex one)

head -2 filename | tail -1
for V in $bla
do
    ((i++))
    echo "$i - V='$V'"
done

in one line

for V in $bla; do ((i++)); echo "$i - V='$V'"; done