Sponsored Content
Top Forums Shell Programming and Scripting [Solved] Find Specific records from file and add totals into variables Post 302341260 by veeru on Wednesday 5th of August 2009 11:15:40 AM
Old 08-05-2009
I don't want to rewrite everything because I have lot other validations included in the same script. My below code is working for total but not for sum because I have some decimals in my sum.

Code:
total=0
summ=0
grep "Records Sent:" filename | while read line
do
tot=`$line | cut -f3 -d " "`
suu=`$line | cut -f5 -d " "`
total=`expr $total + $tot`
summ=`expr $summ + $suu`
done
echo "Total = $total"
echo "Sum = $summ"

The above code is working to get the total but not for sum because I have some decimals in sum. please let me know how to get rid of those errors

Errors:

expr: non-numeric argument
expr: syntax error
expr: syntax error
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extarct specific records from wide file

I have a file which is 5 million records. And each records has 412 fields has delimited by "|". So that makes each records to be 2923 bytes long. I wanted to extract specific records like top 100 or 2500 - 5000, 50001 - 10000 etc. from this file. I tried using head command for top 100 records,... (1 Reply)
Discussion started by: acheepi
1 Replies

2. Shell Programming and Scripting

cut specific records from a file

I am trying to cut the first 10 characters from a file only if the file has 'xyz' in field 185-188. I tried this cat filename | cut -c1-10 but this gives me all the records regardless of what is in field 185-188. Is this doable ? Thanks in advance for responses. (2 Replies)
Discussion started by: jxh461
2 Replies

3. UNIX for Dummies Questions & Answers

Cut specific fields from a file containing multiline records

Hi, I am looking for a method to get column13 to column 50 data from the 1st line of a multiline reord. The records are stored in a large file and are separated by newline. sample format is (data in red is to be extracted) <header> A001dfhskhfkdsh hajfhksdhfjh... (3 Replies)
Discussion started by: sunayana3112
3 Replies

4. UNIX for Dummies Questions & Answers

Grep specific records from a file of records that are separated by an empty line

Hi everyone. I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this: ID: 20 Name: X Age: 19 ID: 21 Name: Z ID: 22 Email: xxx@yahoo.com Name: Y Age: 19 I want to grep records that... (4 Replies)
Discussion started by: Atrisa
4 Replies

5. Shell Programming and Scripting

[Solved] Find duplicate and add pattern in sed/awk

<Update> I have the solution: sed 's/\{3\}/&;&;---;4/' The thread can be marked as solved! </Update> Hi There, I'm working on a script processing some data from a website into cvs format. There is only one final problem left I can't find a solution. I've processed my file... (0 Replies)
Discussion started by: lolworlds
0 Replies

6. Shell Programming and Scripting

Extract error records based on specific criteria from Unix file

Hi, I look for a awk one liner for below issue. input file ABC 1234 abc 12345 ABC 4567 678 XYZ xyz ght 678 ABC 787 yyuu ABC 789 7890 777 zxr hyip hyu mno uii 678 776 ABC ty7 888 All lines should be started with ABC as first field. If a record has another value for 1st... (7 Replies)
Discussion started by: ratheesh2011
7 Replies

7. Shell Programming and Scripting

[Solved] Working with date (add minutes using variables)

Dear all, today I'm scratching my head with a simple (I believe) issue. Working with date is quite simple, so if I Need to add some seconds to current time, I'll use: date --date='+30 seconds' +"%Y-%m-%d %H:%M:%S"But, how to pass the value to add from a variable? I tried the following without... (2 Replies)
Discussion started by: Lord Spectre
2 Replies

8. Shell Programming and Scripting

[SOLVED] nawk FS using pipe read variables from file

I have a file data_1.out which contains: 1|abc mail|mail subject|mail body 2|def mail|mail subject|def mail body I am trying to read the variables from data_1.out and use them to print to 2 different files based on the id (first_column) The problem is I am not able to read the file... (8 Replies)
Discussion started by: sol_nov
8 Replies

9. Shell Programming and Scripting

[Solved] How to print specific text from a file?

Hi All, I have the below text file from which I have to cut particular section starting from PTR_Security_Rpeorting.cpf to PTR_Security_Reporting_Env93_export. Report Model............: "D:\Cognos_Publishing\tmp.a2R94KLQec"\PTR_Security_Reporting.cpf Report Output Script....:... (4 Replies)
Discussion started by: Vikram_Tanwar12
4 Replies

10. UNIX for Beginners Questions & Answers

Find records with specific characters in 2 nd field

Hi , I have a requirement to read a file ( 5 fields , ~ delimited) and find the records which contain anything other than Alphabets, Numbers , comma ,space and dot . ie a-z and A-Z and 0-9 and . and " " and , in 2nd field. Once I do that i would want the result to have field1|<flag> flag can... (2 Replies)
Discussion started by: ashwin3086
2 Replies
inc::Module::Install::DSL(3)				User Contributed Perl Documentation			      inc::Module::Install::DSL(3)

NAME
inc::Module::Install::DSL - Domain Specific Language for Module::Install SYNOPSIS
use inc::Module::Install::DSL 0.80; all_from lib/ADAMK/Repository.pm requires File::Spec 3.29 requires File::pushd 1.00 requires File::Find::Rule 0.30 requires File::Find::Rule::VCS 1.05 requires File::Flat 0 requires File::Remove 1.42 requires IPC::Run3 0.034 requires Object::Tiny 1.06 requires Params::Util 0.35 requires CPAN::Version 5.5 test_requires Test::More 0.86 test_requires Test::Script 1.03 install_script adamk requires_external_bin svn DESCRIPTION
One of the primary design goals of Module::Install is to simplify the creation of Makefile.PL scripts. Part of this involves the gradual reduction of any and all superfluous characters, with the ultimate goal of requiring no non-critical information in the file. Module::Install::DSL is a simple Domain Specific Language based on the already-lightweight Module::Install command syntax. The DSL takes one command on each line, and then wraps the command (and its parameters) with the normal quotes and semi-colons etc to turn it into Perl code. SUPPORT
Bugs should be reported via the CPAN bug tracker at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Module-Install> For other issues contact the author. AUTHORS
Adam Kennedy <adamk@cpan.org> COPYRIGHT
Copyright 2008 - 2012 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.16.3 2012-03-01 inc::Module::Install::DSL(3)
All times are GMT -4. The time now is 08:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy