Sponsored Content
Top Forums Shell Programming and Scripting Awk to add selected row column data Post 302613163 by Ironguru on Monday 26th of March 2012 10:25:51 PM
Old 03-26-2012
Awk to add selected row column data

Looks at the most efficient way to add up the column of data based off of the rows.

Random data
Name-Number-ID
Sarah-2.0-15
Bob-6.3-15
Sally-1.0-10
James-1.0-10
Scotty-10.7-15

So I would select all those who have ID = 15 and then add up total number
Code:
read - p "Enter ID number" Num

cut -d "-" -f 2-3 file.txt > temp.txt
awk -F "-" '/' $Num '/ {hour += $2} END {Print "Total is: " %.2f\n, number}' temp.txt

Not sure on the syntax or if hour+= should be $2 or $3Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Format - Inventory Row data into Column - Awk - Nawk

Hi All, I have the following file that has computer data for various pcs in my network... Snap of the file is as follows ******************************************************************************* Serial 123456 Computer IP Address lo0:... (1 Reply)
Discussion started by: aavam
1 Replies

2. Shell Programming and Scripting

shell script(Preferably awk or sed) to print selected number of columns from each row

Hi Experts, The question may look very silly by seeing the title, but please have a look at it clearly. I have a text file where the first 5 columns in each row were supposed to be attributes of a sample(like sample name, number, status etc) and the next 25 columns are parameters on which... (3 Replies)
Discussion started by: ks_reddy
3 Replies

3. Shell Programming and Scripting

row to column and position data in to fixed column width

Dear friends, Below is my program and current output. I wish to have 3 or 4 column output in order to accomodate in single page. i do have subsequent command to process after user enter the number. Program COUNT=1 for MYDIR in `ls /` do VOBS=${MYDIR} echo "${COUNT}. ${MYDIR}" ... (4 Replies)
Discussion started by: baluchen
4 Replies

4. Shell Programming and Scripting

Moving data from a specified column/row to another column/row

Hello, I have an input file like the following: 11_3_4 2_1_35 3_15__ _16989 Where '_' is a space. The data is in a table. Is there a way for the program to prompt the user for x1,y1 and x2,y2, where x1,y1 is the desired number (for example x=6 y=4 is a value of 4) and move to a desired spot... (2 Replies)
Discussion started by: jl487
2 Replies

5. Shell Programming and Scripting

Subtracting each row from the first row in a single column file using awk

Hi Friends, I have a single column data like below. 1 2 3 4 5 I need the output like below. 0 1 2 3 4 where each row (including first row) subtracting from first row and the result should print below like the way shown in output file. Thanks Sid (11 Replies)
Discussion started by: ks_reddy
11 Replies

6. UNIX for Advanced & Expert Users

Convert column data to row data using shell script

Hi, I want to convert a 3-column data to 3-row data using shell script. Any suggestion in this regard is highly appreciated. Thanks. (4 Replies)
Discussion started by: sktkpl
4 Replies

7. Shell Programming and Scripting

awk command to print only selected rows in a particular column specified by column name

Dear All, I have a data file input.csv like below. (Only five column shown here for example.) Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 3,2,4,5,6 5,3,5,5,6 From this I want the below output Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 where the second column... (4 Replies)
Discussion started by: ks_reddy
4 Replies

8. Shell Programming and Scripting

awk - script help: column to row format of data allignment?

Experts Good day, I have the following data, file1 BRAAGRP1 A2X B2X C2X D2X BRBGRP12 A3X B3X Z10 D09 BRC1GRP2 LO01 (4 Replies)
Discussion started by: rveri
4 Replies

9. UNIX for Dummies Questions & Answers

awk to print first row with forth column and last row with fifth column in each file

file with this content awk 'NR==1 {print $4} && NR==2 {print $5}' file The error is shown with syntax error; what can be done (4 Replies)
Discussion started by: cdfd123
4 Replies

10. Shell Programming and Scripting

How to get row data printed in column using awk?

Hi team, I have below sample file. $ cat sample dn: MSISDN=400512345677,dc=msisdn,ou=NPSD,serv=CSPS,ou=servCommonData,dc=stc structuralObjectClass: NphData objectClass: NphData objectClass: MSISDN entryDS: 0 nodeId: 35 createTimestamp: 20170216121047Z modifyTimestamp: 20170216121047Z... (3 Replies)
Discussion started by: shanul karim
3 Replies
MPI_KMEANS(1)						      General Commands Manual						     MPI_KMEANS(1)

NAME
mpi_kmeans - K-Means clustering tool SYNOPSIS
mpi_kmeans [options] DESCRIPTION
mpi_kmeans is a program that uses k-means clustering to produce a list of cluster centers. The resulting data can be used by mpi_assign(1) to assign points to those cluster centers. OPTIONS
A summary of options is included below. Generic Options: --help Produce help message Input/Output Options: --data file Training file, one datum per line (default: "data.txt") --output file Output file, one cluster center per line (default: "output.txt") K-Means Options: --k num Number of clusters to generate (default: 100) --restarts num Number of k-means restarts (default: 0 = single run) --maxiter num Maximum number of k-means iterations (default: 0 = infinity) EXAMPLES
mpi_kmeans --k 2 --data example.txt --output clusters.txt SEE ALSO
mpi_assign(1) AUTHOR
mpi_kmeans was written by Peter Gehler <peter.gehler@tuebingen.mpg.de>. This manual page was written by Christian Kastner <debian@kvr.at>, for the Debian project (and may be used by others). April 11, 2011 MPI_KMEANS(1)
All times are GMT -4. The time now is 07:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy