Sponsored Content
Top Forums Shell Programming and Scripting Division of columns from two files Post 302829949 by andrewps on Sunday 7th of July 2013 11:42:33 AM
Old 07-07-2013
Division of columns from two files

I have two text files T1 and T2

T1 looks as follows

Code:
Name         All                        Maths               Science             English                 Social   
Anie         48/18  =   2.7        44/17  =   2.6         20/6   =   3.3        24/11  =   2.2            NA  
Edwin        134/41  =   3.3        96/30  =   3.2        34/10  =   3.4        50/18  =   2.8        12/2   =   6.0
Andrew       14/9   =   1.6        14/9   =   1.6         6/3   =   2.0         8/6   =    1.3             NA

T2 looks as follows

Code:
Name         All                        Maths               Science             English                 Social 
Anie         28/19  =   1.5        26/18  =   1.4         5/4   =   1.2         21/14  =   1.5             NA  
Edwin         64/16  =   4.0        43/12  =   3.6        28/6   =   4.7        15/6   =   2.5            18/3 =  6.0
Andrew        118/41  =   2.9       110/39  =   2.8        61/17  =   3.6        49/22  =  2.2            NA

I would like to divide the answers of each column as shown below.


output

Code:
Name         All                        Maths               Science             English                 Social 
Anie         2.7/1.5 = 1.8            2.6/1.4 = 1.86      3.3/1.2 = 2.75      2.2/1.5 = 1.45             NA
Edwin        3.3/4.0 = 0.83           3.2/3.6 = 0.89      3.4/4.7 = 0.72      2.8/2.5 = 1.12            6.0/6.0 = 1.0
Andrew       1.6/2.9 = 0.55           1.6/2.8 = 0.57      2.0/3.6 = 0.56      1.3/2.2 = 0.59             NA


Last edited by Scrutinizer; 07-07-2013 at 01:15 PM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

division problem

how can i show the value when i divide a number where the dividend is greater then the divisor. for example... 3 divided by 15 ---> let x=3/15 when i do this in the shell environment it gives me an output of 0. please help me. thanks. (3 Replies)
Discussion started by: inquirer
3 Replies

2. Shell Programming and Scripting

division by 0 error

Hi, I am writing a script that among other things will be checking for various files on mount points. One of the conditions is that unless the server has failed over the df command will show root ( / ). If when checking the files the script comes across /, I want it to skip it, otherwise to... (2 Replies)
Discussion started by: cat55
2 Replies

3. Shell Programming and Scripting

How to compare 2 files & get only few columns based on a condition related to both files?

Hiiiii friends I have 2 files which contains huge data & few lines of it are as shown below File1: b.dat(which has 21 columns) SSR 1976 8 12 13 10 44.00 39.0700 70.7800 7.0 0 0.00 0 2.78 0.00 0.00 0 0.00 2.78 0 NULL ISC 1976 8 12 22 32 37.39 36.2942 70.7338... (6 Replies)
Discussion started by: reva
6 Replies

4. Shell Programming and Scripting

division by zero

Hello, I am searching for a way to calculate for example 10/100 within a shellscript and the result should be 0.1 and not just 0. Every alternative i tried just results 0 Thank you in advance 2retti (6 Replies)
Discussion started by: 2retti
6 Replies

5. UNIX for Dummies Questions & Answers

Help in division

hi, The below commands result only the whole number(not giving the decimal values). pandeeswaran@ubuntu:~$ echo 1,2,3,4|sed 's/,/\//g'|bc 0 pandeeswaran@ubuntu:~$ echo 1000,2,3|sed 's/,/\//g'|bc 166 How to make it to return the decimal values? Thanks (5 Replies)
Discussion started by: pandeesh
5 Replies

6. Shell Programming and Scripting

Combine columns from many files but keep them aligned in columns-shorter left column issue

Hello everyone, I searched the forum looking for answers to this but I could not pinpoint exactly what I need as I keep having trouble. I have many files each having two columns and hundreds of rows. first column is a string (can have many words) and the second column is a number.The files are... (5 Replies)
Discussion started by: isildur1234
5 Replies

7. UNIX for Dummies Questions & Answers

Division of wc output

I have a function that outputs 3 lines for each result and I want to know how many results there are. so for example function | wc -l 24 but I want to see the result 8. so is there a easy way to divide the result? (5 Replies)
Discussion started by: yatici
5 Replies

8. Shell Programming and Scripting

Compare 2 csv files by columns, then extract certain columns of matcing rows

Hi all, I'm pretty much a newbie to UNIX. I would appreciate any help with UNIX coding on comparing two large csv files (greater than 10 GB in size), and output a file with matching columns. I want to compare file1 and file2 by 'id' and 'chain' columns, then extract exact matching rows'... (5 Replies)
Discussion started by: bkane3
5 Replies

9. Shell Programming and Scripting

Adding columns from 2 files with variable number of columns

I have two files, file1 and file2 who have identical number of rows and columns. However, the script is supposed to be used for for different files and I cannot know the format in advance. Also, the number of columns changes within the file, some rows have more and some less columns (they are... (13 Replies)
Discussion started by: maya3
13 Replies

10. UNIX for Beginners Questions & Answers

How to use "awk" to print columns from different files in separate columns?

Hi, I'm trying to copy and paste the sixth column from a bunch of files into a single file having each column pasted in separate columns (and not one after each other in just one column.) I tried this code but works only partially because it copied and pasted 50 rows of each column... (6 Replies)
Discussion started by: Frastra
6 Replies
GSLP(1) 							    Ghostscript 							   GSLP(1)

NAME
gslp - Format and print text using ghostscript gsbj - Format and print text for BubbleJet printer using ghostscript gsdj - Format and print text for DeskJet printer using ghostscript gsdj500 - Format and print text for DeskJet 500 BubbleJet using ghostscript gslj - Format and print text for LaserJet printer using ghostscript SYNOPSIS
gslp -12BclqRr -b<header> -f<font> -F<hfont> -L<lines> -p<outfile> -T<n> --add-to-space <units> --add-to-width <units> --columns <n> --detect --first-page <n> --kern <file.afm> --last-page <n> --(heading|footing)-(left|center|right) <string> --margin-(top|bot- tom|left|right) <inches> --no-eject-(file|formfeed) --spacing <n> [gs options] [files] gsbj [options] [files] gsdj [options] [files] gsdj500 [options] [files] gslj [options] [files] DESCRIPTION
This utility provides functionality approximately equivalent to the Unix enscript(1) program. It prints plain text files using a single font. It currently handles tabs and formfeeds, but not backspaces. It will line-wrap when using fixed-pitch fonts. It will also do kern- ing and width adjustment. The default device (-sDEVICE=) and resolution (-r) are as follows: gslp epson 180 gsbj bj10e 180 gsdj deskjet 300 gsdj500 djet500 300 gslj laserjet 300 By default the current date is formatted as the center header. OPTIONS
Standard switches implemented: -12BclqRr -b<header> -f<font> -F<hfont> -L<lines> -p<outfile> Sun switches implemented: -T<n> set tab width Switches ignored: -GghKkmow -# -C -d -J -n -P -S -s -t -v Switches added: --add-to-space <units> add the given number of 1/72" units to the width of each space (may be negative) --add-to-width <units> add the given number of 1/72" units to the width of each character (may be negative) --columns <n> print in <n> columns --detect treat the file as PostScript if it starts with %! --first-page <n> start printing at page <n> --kern <file.afm> kern using information from the given .AFM file --last-page <n> stop printing after page <n> --(heading|footing)-(left|center|right) <string> set the heading/footing fields; use -B first to clear --margin-(top|bottom|left|right) <inches> set a margin --no-eject-(file|formfeed) end-of-file/FF only starts a new column, not a new sheet --spacing <n> use double (n=2), triple (n=3), etc. spacing Also, the string %# in a heading or footing is replaced with the page #. SEE ALSO
gs(1) VERSION
This document was last revised for Ghostscript version 8.63. AUTHOR
Artifex Software, Inc. are the primary maintainers of Ghostscript. This manpage by George Ferguson. 8.63 1 August 2008 GSLP(1)
All times are GMT -4. The time now is 03:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy