2retti
August 27, 2010, 3:37am
1
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
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.
2retti
August 27, 2010, 3:58am
3
pinga123:
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
2retti
August 27, 2010, 4:11am
5
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
frans
August 27, 2010, 5:42am
7
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