How to handle one value below the other


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to handle one value below the other
# 1  
Old 08-27-2010
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

Smilie

Thank you in advance
2retti

Last edited by 2retti; 08-27-2010 at 04:55 AM..
# 2  
Old 08-27-2010
Code:
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.
# 3  
Old 08-27-2010
Quote:
Originally Posted by pinga123
Code:
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.

Last edited by 2retti; 08-27-2010 at 05:07 AM..
# 4  
Old 08-27-2010
Code:
awk 'NR==2{print $0}' filename

This will display 2nd line of file named filename
This User Gave Thanks to pinga123 For This Post:
# 5  
Old 08-27-2010
Quote:
Originally Posted by pinga123
Code:
awk 'NR==2{print $0}' filename

This will display 2nd line of file named filename
Thank you!!!! Thats exactly what need!!!
# 6  
Old 08-27-2010
Another way of doing the same thing (compact one)

Code:
awk 'NR==2' filename

Another way of doing the same thing (complex one)

Code:
head -2 filename | tail -1


Last edited by pinga123; 08-27-2010 at 05:24 AM..
# 7  
Old 08-27-2010
for loop i shell (bash)

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

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Handle space in directory name

I have two servers in subject, say server1 and server2. I have shell scripts on server1. We have a directory on server2 from where the files need to be scp to server1. The directory on server2 is having space in its name. I have script on server1 that takes the directory path of server2 as a... (4 Replies)
Discussion started by: Longfellow
4 Replies

2. Shell Programming and Scripting

Handle error

I have a script as below , the script can tar file to the tape , however , it is fail to handle the error , if there is error like the backup file is in writing , then it will echo this is fail ( but the file has successful backup actually , so the backup task is succes , but it still report it is... (6 Replies)
Discussion started by: ust
6 Replies

3. UNIX for Dummies Questions & Answers

Difference between handle to the thread HANDLE and thread identifier pthread_t

This question might be silly but its confusing me a bit: What is the difference between handle to the thread HANDLE and thread identifier pthread_t? ---------- Post updated at 01:52 PM ---------- Previous update was at 01:48 PM ---------- Sorry I saw details and HANDLE is in windows and... (0 Replies)
Discussion started by: rupeshkp728
0 Replies

4. Shell Programming and Scripting

Need help to handle errors during SFTP

Hi, I have written a script that sftp's files from linux box to a IBM machine. Can anybody help me how to handle any errors during SFTP file transfer. I am writing the SFTP commands onto a file and executing that as you can see below. while read line do if ] && ]; then echo "put... (1 Reply)
Discussion started by: ramkiran77
1 Replies

5. Shell Programming and Scripting

~R in between string, how to handle in AWK

Hi, Can any one help how to handle the below situation. Am using Awk script to handle variable When I open the file in VI mode, I see the string as Orange~Rs , but when I cat the file its showing as plain Oranges. When I copied the file over to Windows, am seeing the special character... (3 Replies)
Discussion started by: sp999
3 Replies

6. UNIX for Advanced & Expert Users

Handle Autosys with DST Changes

Hi, I have one confusion regarding DST chnages which are going to happen after October. :confused: :confused: I have few jobs on Autosys which run as per Japan Time. they shoudl not be affected by switiching off of DST time. Our autosys instance server is based on UK which is running on... (0 Replies)
Discussion started by: girdharsourabh
0 Replies

7. Shell Programming and Scripting

handle decimals

Hi All, How we can handle decimals in (Float) in UNIX. a=73 b=5 c=`expr a / b` i am getting 14 but i need full 14.6 . Can any one help me pls? (1 Reply)
Discussion started by: subin_bala
1 Replies

8. Shell Programming and Scripting

[Beginner] Handle Files

Hi, How can I check if a text files is empty? (With Bash Shell) (5 Replies)
Discussion started by: DNAx86
5 Replies

9. UNIX for Advanced & Expert Users

How to handle my own mail

I installed sendmail and pine and I could send emails to other people succesffly. However no matter what I try I cannot receive other people's email. The only messages sitting in my pine inbox are system notifications sent to root@knoppix. Then I think the problem is that my mail is handled by... (3 Replies)
Discussion started by: onthetopo
3 Replies

10. Programming

handle core

Hi I am looking for analog of the Windows "try-except" C code statement that enables target applications to gain control when events that normally terminate program execution occur. (1 Reply)
Discussion started by: vlad
1 Replies
Login or Register to Ask a Question