nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Calculations across different lines & columns of a file

This is a discussion on Calculations across different lines & columns of a file within the Shell scripting forums, part of the Development/Scripting category; Thank you for the wonderful guide LSST (I read it at freeos.com). I am very new to shell scripting but ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 09-14-2005, 09:56 PM
Guest
Guest
 
Posts: n/a
Default Calculations across different lines & columns of a file

Thank you for the wonderful guide LSST (I read it at freeos.com).
I am very new to shell scripting but learning by experimentation. I have to write a script to do the following:
There is a file which has to be manipulated in many ways as given after the data in the file below:
Code:
Description   Current Val      Max Val   Err Val
firstparam        5403           8000         0
secondparam        350          10000         0
third param     458950         600000         5
param fourth      8190          10000         0
The calculation I need to do could be as follows:
is (third's curr val + second's curr val) > param fourths maxval ???
scan all values in err val column to chk if any value above 0

Any help in this matter would be highly appreciated
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-15-2005, 05:10 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Ubuntu
Posts: 1,036
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Code:
#!/bin/bash
DATA="data.txt"
# store line number
LNO=0
# numbers
F4=0
F3=0
F2=0
while read line
do
   F1=$(echo $line|awk '{ print $1 }' )
   F2=$(echo $line|awk '{ print $2 }' )
   F3=$(echo $line|awk '{ print $3 }' )
   F4=$(echo $line|awk '{ print $4 }' )
   LNO=$( expr $LNO + 1)
   # echo $F1 $F2 $F3 $F4
   # Description ==> $F1
   # Current Val  ==> $F2
   # Max Val  ==> $F3
   # Err Val ==> $F4
   # you can do the math on $F4 $F3 line by line now
   [ $F4 -gt 0 ] && echo "err val column $F4 value above 0 ($DATA line # $LNO)"
done < $DATA
Try above code; if have a questions please reply back
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
  #3 (permalink)  
Old 09-16-2005, 05:18 AM
QL
Guest
 
Posts: n/a
Default

Thank you for that code, but after posting here I went back to the tutorials and did some logic building again for the requirement I had in mind. I worked out some other method than what you mentioned (tho the commands are similar to what you've used here). As I mentioned, the requirement is calculations across the rows...what I meant is value of row3, col2 added to row4, col2 added to row5, 2 and then compared to value of row6, col4 and based on that perform some other tasks like mailing the user...ill try to post what i have done already tomorrow as its quite late now and i am sleepy too...thanks indeed for your response.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
How to print some lines from a file Prahlad Shell scripting 3 04-24-2008 12:25 AM
Script to display number of lines and words from a file newbewie Shell scripting 2 12-07-2007 11:37 PM
Create output in columns rakeshrhn Shell scripting 5 12-07-2007 07:27 PM
help me in editing this columns sureshbup Shell scripting 1 12-12-2006 03:29 PM
rearranging columns in a text file sureshbup Shell scripting 2 12-06-2006 10:43 AM


All times are GMT +5.5. The time now is 05:32 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36