Sponsored Content
Top Forums Shell Programming and Scripting Totals in a file - incorrectly displaying Post 302479906 by mcclunyboy on Monday 13th of December 2010 08:21:06 AM
Old 12-13-2010
Totals in a file - incorrectly displaying

Afternoon,

I have a script which creates/modifies data into a formatted csv.

The trailer record should display 2 columns, the first is a static entry of "T" to identify it as a trailer record. The 2nd is a total of amounts in a column throughout the entire file.

My total isn't displaying correctly. I do not use decimal points and the following code is not displaying the final digit. It displays every other digit correctly (just missing the 2nd digit after the decimal point)

At the minute I have
Code:
 $(awk '{s+=$3}END {print "T, "s}

On a seperate note, considering it is the 3rd column I am totalling, the header record has 3 columns which I do not want included - it seems to work just now ever though the header has a fixed number in the 3rd column (does awk count the $'s from 0 or from 1?)

Thanks
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Writing to a log file incorrectly

I have this script: #!/bin/ksh ######### Environment Setup ######### PATH=/gers/nurev/menu/pub/sbin:/gers/nurev/menu/pub/bin:/gers/nurev/menu/pub/mac :/gers/nurev/menu/adm/sbin:/gers/nurev/menu/adm/bin:/gers/nurev/menu/adm/mac:/ge... (5 Replies)
Discussion started by: heprox
5 Replies

2. Shell Programming and Scripting

Calculating totals in AWK

Hello, With the following small script I list the size of documents belonging to a certain user by each time selecting the bytes-field of that file ($7). Now it fills the array with every file it finds so in the end the output of some users contains up to 200.000 numbers. So how can I calculate... (7 Replies)
Discussion started by: Hille
7 Replies

3. Shell Programming and Scripting

summarising totals in awk

awk ' FILENAME == "all" { balance += substr($0,17,13) dt = substr($0,6,8) } END { for ( name in balance ) printf("%013s %3s of %8s\n", balance/100,name,dt) | "sort " } ' all > summation using this code i wanted to take summary totals of... (3 Replies)
Discussion started by: paresh n doshi
3 Replies

4. Shell Programming and Scripting

[Solved] Find Specific records from file and add totals into variables

Hi Eveyone, I am working on one shell script to find the specific records from data file and add the totals into variables and print them. you can find the sample data file below for more clarification. Sample Data File: PXSTYL00__20090803USA CHCART00__20090803IND... (7 Replies)
Discussion started by: veeru
7 Replies

5. Shell Programming and Scripting

Report Totals

Hello, I have written a script in a previous server and its being migrated to a new server. I'm trying to debug my script since i've had to make minor changes to it to get it to work. I'm having a hard time getting my totals to populate here is the syntax DUMP_COUNT=`sqlplus -S... (4 Replies)
Discussion started by: senormarquez
4 Replies

6. Shell Programming and Scripting

Trying to combine upload and download totals from txt file by ip address

I have two files, uploads.txt and downloads.txt. I would like to combine the columns of these files based on the ip address. How can I best do this? Uploads.txt 192.168.0.147 1565369 192.168.0.13 1664855 192.168.0.6 1332868 Downloads.txt 192.168.0.147 9838820 192.168.0.18 12051718... (7 Replies)
Discussion started by: zanyspydude
7 Replies

7. Shell Programming and Scripting

Grand totals in awk

I have a one-liner script like this that gives a total of everything in various directories: for i in *; do (cd $i && cd statelist && echo $i && ls -la |awk 'NR>3 {SUM += $5}\ END { print "Total number of elements " SUM }');done It works just great but at the end I want to print a grand... (3 Replies)
Discussion started by: newbie2010
3 Replies

8. UNIX for Beginners Questions & Answers

Ls incorrectly says file not found in sftp.

Hi all When I sftp to an Oracle cloud server, to a folder where there are more than 10k files, and list a small subset of files, it works OK. When I try list more than 10k files, it says file not found. Example output below. (FYI ls/mget with 6k files works OK on this server) Has anyone... (3 Replies)
Discussion started by: pdinsdale
3 Replies

9. Shell Programming and Scripting

Large File masking incorrectly happening Ç delimeter issue

The OS version is Red Hat Enterprise Linux Server release 6.10 I have a script to mask some columns with **** in a data file which is delimeted with Ç , I am using awk for the masking , when I try to mask a small file the awk works fine and masks the required column , but when the file is... (6 Replies)
Discussion started by: LinuxUser8092
6 Replies
pr(1)								   User Commands							     pr(1)

NAME
pr - print files SYNOPSIS
/usr/bin/pr [+ page] [-column] [-adFmrt] [-e [char] [gap]] [-h header] [-i [char] [gap]] [-l lines] [-n [char] [width]] [-o offset] [-s [char]] [-w width] [-fp] [file]... /usr/xpg4/bin/pr [+ page] [-column | -c column] [-adFmrt] [-e [char] [gap]] [-h header] [-i [char] [gap]] [-l lines] [-n [char] [width]] [-o offset] [-s [char]] [-w width] [-fp] [file]... DESCRIPTION
The pr utility is a printing and pagination filter. If multiple input files are specified, each is read, formatted, and written to standard output. By default, the input is separated into 66-line pages, each with: o a 5-line header that includes the page number, date, time and the path name of the file o a 5-line trailer consisting of blank lines If standard output is associated with a terminal, diagnostic messages will be deferred until the pr utility has completed processing. When options specifying multi-column output are specified, output text columns will be of equal width; input lines that do not fit into a text column will be truncated. By default, text columns are separated with at least one blank character. OPTIONS
The following options are supported. In the following option descriptions, column, lines, offset, page, and width are positive decimal integers; gap is a non-negative decimal integer. Some of the option-arguments are optional, and some of the option-arguments cannot be specified as separate arguments from the preceding option letter. In particular, the -s option does not allow the option letter to be sepa- rated from its argument, and the options -e, -i, and -n require that both arguments, if present, not be separated from the option letter. The following options are supported for both /usr/bin/pr and /usr/xpg4/bin/pr: +page Begins output at page number page of the formatted input. -column Produces multi-column output that is arranged in column columns (default is 1) and is written down each column in the order in which the text is received from the input file. This option should not be used with -m. The -e and -i options will be assumed for multiple text-column output. Whether or not text columns are produced with identical vertical lengths is unspecified, but a text column will never exceed the length of the page (see the -l option). When used with -t, use the minimum number of lines to write the output. -a Modifies the effect of the -column option so that the columns are filled across the page in a round-robin order (for example, when column is 2, the first input line heads column 1, the second heads column 2, the third is the second line in column 1, and so forth). -d Produces output that is double-spaced; append an extra NEWLINE character following every NEWLINE character found in the input. -e[char][gap] Expands each input TAB character to the next greater column position specified by the formula n *gap+1, where n is an integer >0. If gap is 0 or is omitted, it defaults to 8. All TAB characters in the input will be expanded into the appropriate number of SPACE characters. If any non-digit character, char, is specified, it will be used as the input tab character. -f Uses a FORMFEED character for new pages, instead of the default behavior that uses a sequence of NEWLINE char- acters. Pauses before beginning the first page if the standard output is associated with a terminal. -h header Uses the string header to replace the contents of the file operand in the page header. -l lines Overrides the 66-line default and reset the page length to lines. If lines is not greater than the sum of both the header and trailer depths (in lines), pr will suppress both the header and trailer, as if the -t option were in effect. -m Merges files. Standard output will be formatted so pr writes one line from each file specified by file, side by side into text columns of equal fixed widths, in terms of the number of column positions. Implementations support merging of at least nine files. -n[char][width] Provides width-digit line numbering (default for width is 5). The number will occupy the first width column positions of each text column of default output or each line of -m output. If char (any non-digit character) is given, it will be appended to the line number to separate it from whatever follows (default for char is a TAB character). -o offset Each line of output will be preceded by offset <space>s. If the -o option is not specified, the default offset is 0. The space taken will be in addition to the output line width (see -w option below). -p Pauses before beginning each page if the standard output is directed to a terminal (pr will write an ALERT character to standard error and wait for a carriage-return character to be read on /dev/tty). -r Writes no diagnostic reports on failure to open files. -s [char] Separates text columns by the single character char instead of by the appropriate number of SPACE characters (default for char is the TAB character). -t Writes neither the five-line identifying header nor the five-line trailer usually supplied for each page. Quits writing after the last line of each file without spacing to the end of the page. -w width Sets the width of the line to width column positions for multiple text-column output only. If the -w option is not specified and the -s option is not specified, the default width is 72. If the -w option is not specified and the -s option is specified, the default width is 512. For single column output, input lines will not be truncated. /usr/bin/pr The following options are supported for /usr/bin/pr only: -F Folds the lines of the input file. When used in multi-column mode (with the -a or -m options), lines will be folded to fit the current column's width. Otherwise, they will be folded to fit the current line width (80 col- umns). -i[char][gap] In output, replaces SPACE characters with TAB characters wherever one or more adjacent SPACE characters reach column positions gap+1, 2*gap+1, 3*gap+1, and so forth. If gap is 0 or is omitted, default TAB settings at every eighth column position are assumed. If any non-digit character, char, is specified, it will be used as the out- put TAB character. /usr/xpg4/bin/pr The following options are supported for /usr/xpg4/bin/pr only: -F Uses a FORMFEED character for new pages, instead of the default behavior that uses a sequence of NEWLINE charac- ters. -i[char][gap] In output, replaces multiple SPACE characters with TAB characters wherever two or more adjacent SPACE characters reach column positions gap+1, 2*gap+1, 3*gap+1, and so forth. If gap is 0 or is omitted, default TAB settings at every eighth column position are assumed. If any non-digit character, char, is specified, it will be used as the output TAB character. OPERANDS
The following operand is supported: file A path name of a file to be written. If no file operands are specified, or if a file operand is -, the standard input will be used. EXAMPLES
Example 1 Printing a numbered list of all files in the current directory example% ls -a | pr -n -h "Files in $(pwd)." Example 2 Printing files in columns This example prints file1 and file2 as a double-spaced, three-column listing headed by file list: example% pr -3d -h "file list" file1 file2 Example 3 Writing files with expanded column tabs The following example writes file1 on file2, expanding tabs to columns 10, 19, 28, ... example% pr -e9 -t <file1 >file2 ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of pr: LANG, LC_ALL, LC_CTYPE, LC_MES- SAGES, LC_TIME, TZ, and NLSPATH. EXIT STATUS
The following exit values are returned: 0 Successful completion. >0 An error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: /usr/bin/pr +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |CSI |Enabled | +-----------------------------+-----------------------------+ /usr/xpg4/bin/pr +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWxcu4 | +-----------------------------+-----------------------------+ |CSI |Enabled | +-----------------------------+-----------------------------+ |Interface Stability |Committed | +-----------------------------+-----------------------------+ |Standard |See standards(5). | +-----------------------------+-----------------------------+ SEE ALSO
expand(1), lp(1), attributes(5), environ(5), standards(5) SunOS 5.11 18 Mar 1997 pr(1)
All times are GMT -4. The time now is 10:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy