Sponsored Content
Full Discussion: Adding in Awk
Top Forums Shell Programming and Scripting Adding in Awk Post 302614239 by CarloM on Wednesday 28th of March 2012 11:03:19 AM
Old 03-28-2012
NR is a built-in awk variable for the current record (line) number.

%5 is modulo 5 (remainder after dividing by 5, integer arithmetic).
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Adding a new field using sed or awk?

I have a bcp file that contains 10 fields. These fields are separated by a tab. How can I add my name as a new field in the 8th position for every record? I've been playing w/ sed and awk but can't seem to figure this out. (3 Replies)
Discussion started by: sasabune
3 Replies

2. Shell Programming and Scripting

Help with awk adding spaces.

I have a file that contains... elm,mail elm,lisp,composer,cd,ls,cd,ls,cd,ls,zcat,|,tar,-xvf,ls,cd,ls,cd,ls,vi,ls,cd,ls,vi,elm,-f,ls,rm,ls,cd,ls,vi,vi,ls,vi,ls,cd,ls,elm,cd,ls,cd,ls,vi,vi,vi,ls,vi,ls,i,vi,ls,cp,cd,fg,ls,rm,cd,ls,-l,exit elm,mail,biff,elm,biff,elm,elm elm,ls ... (2 Replies)
Discussion started by: Bandit390
2 Replies

3. Shell Programming and Scripting

awk-adding a column to a file

Hello Friends, i used awk to sum up total size of files under a directory (with the help of examples, threads here). ls -l | awk '/^-/ {total += $5} END {printf "%15.0f\n",total}' >> total.txt After each execution of the script total result is appended into a text file: 7010 7794 8890 ... (7 Replies)
Discussion started by: EAGL€
7 Replies

4. UNIX for Dummies Questions & Answers

Adding date when using awk

Hi, I want to print the number of lines of a file along with filename and today's date. Ex: XXX|07-22-2010|8 I am using as wc -c -l file.txt | awk '{print "XXX|",date +"%m-%d-%Y","|",$1}' But this one prints as AAA| 0 | 8 Can anyone please help me on this for printing the date? ... (3 Replies)
Discussion started by: aeroticman
3 Replies

5. Shell Programming and Scripting

Adding column using awk

Hello everyone, I have a file with the following structure: abc xyz 111 222 agf hjhf 787 799 tht yah 878 898 ... ... ... ... ... ... ... ... ... ... ... ... I want to add a column (with a fixed value of 1000) at the end such that it becomes: abc xyz 111 222 1000 agf hjhf 787... (5 Replies)
Discussion started by: ad23
5 Replies

6. Shell Programming and Scripting

Adding A Bump of Numbers with Awk

ok, so i have a bunch of numbers in a file that i'd like to add up. i dont know how to do it. This is how far i've gotten: echo "4 4 5 4 3 4 3 3 4 2 43 3 293 49 23" | sed 's/ / + /g' | awk -F" " I dont want to use the expr command with this as i dont trust it. any advice? thanks (1 Reply)
Discussion started by: SkySmart
1 Replies

7. Shell Programming and Scripting

adding a number with sed or awk.

Hi.. I have this delicate problem..:wall: I have this huge ldif file with entry's like this example below.. And I need to change the following entrys. telephoneNumber: emNotifNumber: billingnumber= BillingNumber: Al these entrys has a number like 012345678 and it needs to add one more... (15 Replies)
Discussion started by: pelama
15 Replies

8. Shell Programming and Scripting

Adding a specified value to a specified column - awk?

Hi everyone! I sometimes need to do some simple arithmetics, like adding a number to a certain column of a file. So I wrote a small function in the .bashrc file, which looks like this shifter() { COL=$1 VAL=$2 FILE=$3 cp $FILE $FILE.shifted awk 'NF==4 {$(( $COL )) = $(( $COL ))... (6 Replies)
Discussion started by: radudownload
6 Replies

9. Shell Programming and Scripting

Awk: adding fields after matching $1

Dear AWK-experts! I did get stuck in the task of combining files after matching fields, so I'm still awkward with learning AWK. There are 2 files: one containing 3 columns with ID, coding status, and score for long noncoding RNAs: file1 (1.txt) (>5000 lines) ... (12 Replies)
Discussion started by: kben
12 Replies

10. Shell Programming and Scripting

Adding tags in between sentences with awk

Hi, I need an awk to modify the following file. It is 2-column tab-separated. Hi PP my VBD name DT is NN . SENT Her PP name VBD is DT the NN same WRT . SENT <s> Hi PP - (6 Replies)
Discussion started by: owwow14
6 Replies
mp(3)							     Library Functions Manual							     mp(3)

NAME
madd, msub, mult, mdiv, gcd, invert, rpow, msqrt, mcmp, min, omin, fmin, m_in, mout, omout, fmout, m_out, sdiv, itom - Performs multiple precision integer arithmetic LIBRARY
Object Code Library (libmp.a) SYNOPSIS
#include <mp.h> #include <stdio.h> typedef struct mint { int len; short *val; } MINT; madd( MINT *a, MINT *b, MINT *c ); msub( MINT *a, MINT *b, MINT *c ); mult( MINT *a, MINT *b, MINT *c ); mdiv( MINT *a, MINT *b, MINT *q, MINT *r ); pow( MINT *a, MINT *b, MINT *m, MINT *c ); gcd( MINT *a, MINT *b, MINT *c ); invert( MINT *a, MINT *b, MINT *c ); rpow( MINT *a, int n, MINT *c ); msqrt( MINT *a, MINT *b, MINT *r ); mcmp( MINT *a, MINT *b ); move( MINT *a, MINT *b ); min( MINT *a ); omin( MINT *a ); fmin( MINT *a, FILE *f ); m_in( MINT *a, int n, FILE *f ); mout( MINT *a ); omout( MINT *a ); fmout( MINT *a, FILE *f ); m_out( MINT *a, int n, FILE *f ); sdiv( MINT *a, short n, MINT *q, short *r ); *itom( short n ); DESCRIPTION
These functions perform arithmetic on integers of arbitrary length. The integers are stored using the defined type MINT. Pointers to a MINT can be initialized using the itom() function, which sets the initial value to n. After that, space is managed automatically by the routines. The madd(), msub() , and mult() functions assign to c the sum, difference, and product, respectively, of a and b. The mdiv() function assigns to q and r the quotient and remainder obtained from dividing a by b. The sdiv() function is like the mdiv() function except that the divisor is a short integer n and the remainder is placed in a short integer whose address is given as r. The msqrt() function produces the integer square root of a in b and places the remainder in r. The rpow() function calculates in c the value of a raised to the (``regular'' integral) power n, while the pow() function calculates this with a full multiple precision exponent b and the result is reduced modulo m. The gcd() function returns the greatest common denominator of a and b in c, and the invert() function computes c such that a*c mod b = 1, for a and b relatively prime. The mcmp() function returns a negative, zero, or positive integer value when a is less than, equal to, or greater than b, respectively. The move() function copies a to b. The min() and mout() functions do decimal input and output while the omin() and omout() functions do octal input and output. More gener- ally, the fmin() and fmout() functions do decimal input and output using file f, and m_in() and m_out do input and output with arbitrary radix n. On input, records should have the form of strings of digits terminated by a newline; output records have a similar form. NOTES
Programs which use the multiple-precision arithmetic library must be compiled with -lmp. delim off mp(3)
All times are GMT -4. The time now is 10:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy