Sponsored Content
Top Forums Shell Programming and Scripting Sum product of even/odd lines Post 302892322 by MadeInGermany on Wednesday 12th of March 2014 09:43:44 AM
Old 03-12-2014
A bit shorter
Code:
awk '{out = 0; for(i = 3; i <= NF; i+=2) {out += $(i-1) * $i }; print out}' file

This User Gave Thanks to MadeInGermany For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to get the sum of all the lines in the file

Hi I have the following file, how I will calculate the sum of all the entries in the file. > cat abc 2 3 4 now the sum should be 2+3+4 = 9 (4 Replies)
Discussion started by: sdosanjh
4 Replies

2. Shell Programming and Scripting

print ODD lines

i want to print ODD lines like first ,third then fifth and so on 234,567,ABC,KJL 234,565,ABD,KJL 234,568,ABE,KJL 234,560,ABF,KJL 234,563,ABG,KJL 234,562,ABH,KJL O/P will be like 234,567,ABC,KJL ----->first liine 234,568,ABE,KJL ----->third line 234,563,ABG,KJL ----->fifth line... (6 Replies)
Discussion started by: aaysa123
6 Replies

3. Shell Programming and Scripting

odd problem in read lines from file

Hi, I wrote a small program to read lines from a file and count the lines. The program is as below: filename=$1 count=0 cat $filename | while read -r line do printf "%5d:%s\n" $count "$line" count=$((count + 1)) done echo " $count " After I run the program, the result is... (4 Replies)
Discussion started by: jianma
4 Replies

4. Shell Programming and Scripting

How to search for pattern in odd lines?

Hi friends, I am looking for sed command/script that would search for a given fixed pattern on odd lines and then if it matches, prints the matching pattern and the next line. For example, in the example below, i am looking for pattern 0 and 1011 on odd lines. ########## start of example file... (10 Replies)
Discussion started by: kaaliakahn
10 Replies

5. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum using sed, awk

Hi friends, This is sed & awk type question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers whenever i find it and produce an output file with the sum. For example ###start of input text file #### abc def ghi 1 2 3 4 kjld random... (3 Replies)
Discussion started by: kaaliakahn
3 Replies

6. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum

Hi friends, This is sed & awk type question. It is slightly different from my previous question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers (but no more than 10 numbers in series) whenever i find it and produce an output file with the... (4 Replies)
Discussion started by: kaaliakahn
4 Replies

7. Shell Programming and Scripting

Insert at the beginning of odd lines

Hello people, I am trying with sed to insert some text at the beginning of each odd line of a file but no luck. Can you please help. Awk is also suitable but I am not very familiar with it. Thank you in advance for any help. (7 Replies)
Discussion started by: drbiloukos
7 Replies

8. UNIX for Dummies Questions & Answers

Replace character in odd or even lines

Hello, I'm here again asking for your precious help. I'm writing some code to convert csv files to html. I want to highlight header and also I want to have rows with alternate colors. So far this is my work###Let's format first line only with some color cat $fileIN".tmp1" | sed '1... (7 Replies)
Discussion started by: emare
7 Replies

9. Shell Programming and Scripting

Find to delete lines with pattern and even or odd number

In the below directory I am trying to delete all lines with a .bam extention that have the pattern IonCode_ followed by an even number. I am also trying to delete all lines with a .fastq extention that have the pattern IonCode_ followed by an odd number. I was going to use find but can see all... (6 Replies)
Discussion started by: cmccabe
6 Replies

10. UNIX for Beginners Questions & Answers

awk with sed to combine lines and remove specific odd # pattern from line

In the awk piped to sed below I am trying to format file by removing the odd xxxx_digits and whitespace after, then move the even xxxx_digit to the line above it and add a space between them. There may be multiple lines in file but they are in the same format. The Filename_ID line is the last line... (4 Replies)
Discussion started by: cmccabe
4 Replies
BN_set_bit(3openssl)						      OpenSSL						      BN_set_bit(3openssl)

NAME
BN_set_bit, BN_clear_bit, BN_is_bit_set, BN_mask_bits, BN_lshift, BN_lshift1, BN_rshift, BN_rshift1 - bit operations on BIGNUMs SYNOPSIS
#include <openssl/bn.h> int BN_set_bit(BIGNUM *a, int n); int BN_clear_bit(BIGNUM *a, int n); int BN_is_bit_set(const BIGNUM *a, int n); int BN_mask_bits(BIGNUM *a, int n); int BN_lshift(BIGNUM *r, const BIGNUM *a, int n); int BN_lshift1(BIGNUM *r, BIGNUM *a); int BN_rshift(BIGNUM *r, BIGNUM *a, int n); int BN_rshift1(BIGNUM *r, BIGNUM *a); DESCRIPTION
BN_set_bit() sets bit n in a to 1 (a|=(1<<n)). The number is expanded if necessary. BN_clear_bit() sets bit n in a to 0 (a&=~(1<<n)). An error occurs if a is shorter than n bits. BN_is_bit_set() tests if bit n in a is set. BN_mask_bits() truncates a to an n bit number (a&=~((~0)>>n)). An error occurs if a already is shorter than n bits. BN_lshift() shifts a left by n bits and places the result in r (r=a*2^n). BN_lshift1() shifts a left by one and places the result in r (r=2*a). BN_rshift() shifts a right by n bits and places the result in r (r=a/2^n). BN_rshift1() shifts a right by one and places the result in r (r=a/2). For the shift functions, r and a may be the same variable. RETURN VALUES
BN_is_bit_set() returns 1 if the bit is set, 0 otherwise. All other functions return 1 for success, 0 on error. The error codes can be obtained by ERR_get_error(3). SEE ALSO
bn(3), BN_num_bytes(3), BN_add(3) HISTORY
BN_set_bit(), BN_clear_bit(), BN_is_bit_set(), BN_mask_bits(), BN_lshift(), BN_lshift1(), BN_rshift(), and BN_rshift1() are available in all versions of SSLeay and OpenSSL. OpenSSL-0.9.8 Oct 11 2005 BN_set_bit(3openssl)
All times are GMT -4. The time now is 03:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy