Breaking the sum of a column when specific pattern is found


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Breaking the sum of a column when specific pattern is found
# 8  
Old 05-21-2013
Code:
Code:
  maths                   2            0.0           english                2091            0.2           history               -1            0.0            physics                18            0.0 -------------------------------------- maths                   2            0.0           english                2091            0.2           history               -1            0.0            physics                18            0.0 ------------------------------------- maths                   2            0.0           english                2091            0.2           history               -1            0.0            physics                18            0.0
-----------------------------------------
maths                   2            0.0           english                2091            0.2           history               -1            0.0            physics                18            0.0
------------------------------------------

This is not clear at all, just a long line.
Where did the sum go?
# 9  
Old 05-21-2013
Hi Jotne
Here is the correct file
Code:
maths                   2            0.0
english                2091            0.2
history               -1            0.0
physics                18            0.0
--------------------------------------
maths                   2            0.0
english                2091            0.2
history               -1            0.0
physics                18            0.0
--------------------------------------
maths                   2            0.0
english                2091            0.2
history               -1            0.0
physics                18            0.0
--------------------------------------
maths                   2            0.0
english                2091            0.2
history               -1            0.0
physics                18            0.0
--------------------------------------
maths                   2            0.0
english                2091            0.2
history               -1            0.0
physics                18            0.0
--------------------------------------

Here i need 5 sum up values between "----" and "-----"
# 10  
Old 05-21-2013
Quote:
Originally Posted by Priya Amaresh

[..]

I have tried a set of code like
Code:
[..]
    else
    #total=$LINE
    total=$((total+LINE))
    fi
done < trick

But I get the following error
Code:
./DataCompare.sh
The total number of lines is       19
The previous total is
./DataCompare.sh[14]: ------: 0403-053 Expression is not complete; more tokens expected.

Please correct if am wrong anywhere..
$LINE is not a number but an entire line, so you cannot add it like that..
Have a look at my suggestion in post #3
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sum values of specific column in multiple files, considering ranges defined in another file

I have a file (let say file B) like this: File B: A1 3 5 A1 7 9 A2 2 5 A3 1 3 The first column defines a filename and the other two define a range in that specific file. In the same directory, I have also three more files (File A1, A2 and A3). Here is 10 sample lines... (3 Replies)
Discussion started by: Bastami
3 Replies

2. Shell Programming and Scripting

If first pattern is found, look for second pattern. If second pattern not found, delete line

I had a spot of trouble coming up with a title, hopefully you'll understand once you read my problem... :) I have the output of an ldapsearch that looks like this: dn: cn=sam,ou=company,o=com uidNumber: 7174 gidNumber: 49563 homeDirectory: /home/sam loginshell: /bin/bash uid: sam... (2 Replies)
Discussion started by: samgoober
2 Replies

3. Shell Programming and Scripting

To add a new line with specific text after the pattern is found using sed

hi guys, im trying to add the following line in my xml file <dbrollbacksegs <oa_var="s_db_rollback_segs">NOROLLBACK</dbrollbacksegs> when ever i find the following line <dbsharedpool oa_var="s_dbsharedpool_size">300000000</dbsharedpool> I have succedded till adding a new line... (1 Reply)
Discussion started by: smarlaku
1 Replies

4. Shell Programming and Scripting

Sum of column matching pattern/string

Hi All, I have the following output file created as a result of one script called pattern_daily.log $ cat pattern_daily.log Approved|2|Wed, Oct 24, 2012 11:21:09 AM Declined|1|Wed, Oct 24, 2012 11:21:15 AM Approved|2|Wed, Oct 24, 2012 11:24:08 AM Declined|1|Wed, Oct 24, 2012 11:24:18 AM... (4 Replies)
Discussion started by: Gem_In_I
4 Replies

5. Shell Programming and Scripting

Replace column that matches specific pattern, with column data from another file

Can anyone please help with this? I have 2 files as given below. If 2nd column of file1 has pattern foo1@a, find the matching 1st column in file2 & replace 2nd column of file1 with file2's value. file1 abc_1 foo1@a .... abc_1 soo2@a ... def_2 soo2@a .... def_2 foo1@a ........ (7 Replies)
Discussion started by: prashali
7 Replies

6. Shell Programming and Scripting

awk to sum specific field when pattern matches

Trying to sum field #6 when field #2 matches string as follows: Input data: 2010-09-18-20.24.44.206117 UOWEXEC db2bp DB2XYZ hostname 1 2010-09-18-20.24.44.206117 UOWWAIT db2bp DB2XYZ hostname ... (3 Replies)
Discussion started by: ux4me
3 Replies

7. Shell Programming and Scripting

extract specific line if the search pattern is found

Hi, I need to extract <APPNUMBER> tag alone, if the <college> haas IIT Chennai value. college tag value will have spaces embedded. Those spaces should not be suppresses. My Source file <Record><sno>1</sno><empid>E0001</empid><name>Rejsh suderam</name><college>IIT ... (3 Replies)
Discussion started by: Sekar1
3 Replies

8. Shell Programming and Scripting

Print out specific pattern column data

Input file: adc_0123 haa_1000 bcc_520 adc_0150 bcc_290 adc_0112 haa_8000 adc_0139 haa_7000 Output file: adc_0123 adc_0123 haa_1000 bcc_520 adc_0150 adc_0150 bcc_290 (3 Replies)
Discussion started by: patrick87
3 Replies

9. Shell Programming and Scripting

Print rows, having pattern in specific column...

Hello all, :) I have a pattern file some what like this, cd003 cd005 cd007 cd008 and input file like this, abc cd001 cd002 zca bca cd002 cd003 cza cba cd003 cd004 zca bac cd004 cd005 zac cba cd005 cd006 acz acb cd006 cd007 caz cab cd007 ... (25 Replies)
Discussion started by: admax
25 Replies

10. UNIX for Dummies Questions & Answers

Breaking output for specific pattern

Respected Sirs, I have a text file which is unfortunately unformatted. I have something like 191728/02/06226278 191828/02/06226279 191928/02/06226280 192028/02/06226281 192128/02/06226282 Can some one suggest me the way so that I can store 1917 28/02/06 226278 in different... (2 Replies)
Discussion started by: shoeb_syed
2 Replies
Login or Register to Ask a Question