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 ####
#####end of input file #########
The output should be
##start of output file ####
########### end of output file #################
So the output file is the same as the input file, except the series of numbers is replace by its sum.
I hope it makes sense. If not, please let me know any questions.
Kind Regards,
Last edited by kaaliakahn; 06-26-2012 at 12:28 PM..
Reason: code tags
Hi there
I have a file which has the lines
# Serial number for hostid
EXP_SERIAL_=""
These lines could be anywhere in the file as far as line numbers go, I would like replace these two lines with
# Serial number for hostid $var1
EXP_SERIAL_$var1="$var2"
Is there a quick and simple... (6 Replies)
I have searched the forum for this - forgive me if I missed a previous post.
I have the following file:
blah blah blah
blah blah blah
blah blah blah
blah blah blah
blah blah blah
alter table "informix".esc_acct add constraint (foreign key (fi_id)
references "informix".fi ... (5 Replies)
Hello experts,
I am new to this group and to 'SED' and 'AWK'. I have data (text file) with 5 columns (C_1-5) and 100s of lines (only 10 lines are shown below as an example). I have to find or select only the id numbers (C-1) of specific lines with '90' in the same line (of C_3) AND with '20' in... (6 Replies)
Hello,
I'm trying to figure out how to use sed or awk to delete single lines in a file. By single, I mean lines that are not touching any other lines (just one line with white space above and below).
Example:
one
two
three
four
five
six
seven
eight
I want it to look like: (6 Replies)
Hi,
I have a file with many lines,
then i have following list of lines(line number 5,12,19,5,and 28) i need to replace these lines of a file with another lines as shown below these text
contains special charecter like= (/:;){}
Line_number Text to replace with
5 abc... (1 Reply)
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)
Hi
I would like to know if it is possible to sum some specific fields.
I have this
x;x;x;x;x;x;x;x;467,390,611 Bytes;0.435291 GB;0.062247 GB;0.373045 GB;11,225;157
a;a;a;a;a;a;a;a;13,805,156,846 Bytes;12.857054 GB;1.838559 GB;11.018495 GB;151,063;18,933
b;b;b;b;b;b;b;b;232,797,478,723... (5 Replies)
Data file example
I look for primary and * to isolate the interesting slot number.
slot=`sed '/^primary$/,/\*/!d' filename | tail -1 | sed s'/*//' | awk '{print $1" "$2}'`
Now I want to get the Touch line for only the associate slot number, in this case, because the asterisk... (2 Replies)
Dear Unix Forums,
I am hoping you can help me with a pattern matching problem.
What am I trying to do?
I want to replace multiple lines of a text file (that match a multi-line pattern) with a single line of text. These patterns can span several lines and do not always have the same number of... (10 Replies)
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
LEARN ABOUT FREEBSD
read_random
RANDOM(9) BSD Kernel Developer's Manual RANDOM(9)NAME
arc4rand, arc4random, random, read_random, srandom -- supply pseudo-random numbers
SYNOPSIS
#include <sys/libkern.h>
void
srandom(u_long seed);
u_long
random(void);
void
arc4rand(void *ptr, u_int length, int reseed);
uint32_t
arc4random(void);
#include <sys/random.h>
int
read_random(void *buffer, int count);
DESCRIPTION
The random() function will by default produce a sequence of numbers that can be duplicated by calling srandom() with '1' as the seed. The
srandom() function may be called with any arbitrary seed value to get slightly more unpredictable numbers. It is important to remember that
the random() function is entirely predictable, and is therefore not of use where knowledge of the sequence of numbers may be of benefit to an
attacker.
The arc4rand() function will return very good quality random numbers, slightly better suited for security-related purposes. The random num-
bers from arc4rand() are seeded from the entropy device if it is available. Automatic reseeds happen after a certain timeinterval and after
a certain number of bytes have been delivered. A forced reseed can be forced by passing a non-zero value in the reseed argument.
The read_random() function is used to return entropy directly from the entropy device if it has been loaded. If the entropy device is not
loaded, then the buffer is filled with output generated by random(). The buffer is filled with no more than count bytes. It is advised that
read_random() is not used; instead use arc4rand()
All the bits generated by random(), arc4rand() and read_random() are usable. For example, 'random()&01' will produce a random binary value.
The arc4random() is a convenience function which calls arc4rand() to return a 32 bit pseudo-random integer.
RETURN VALUES
The random() function uses a non-linear additive feedback random number generator employing a default table of size 31 long integers to
return successive pseudo-random numbers in the range from 0 to (2**31)-1. The period of this random number generator is very large, approxi-
mately 16*((2**31)-1).
The arc4rand() function uses the RC4 algorithm to generate successive pseudo-random bytes. The arc4random() function uses arc4rand() to gen-
erate pseudo-random numbers in the range from 0 to (2**32)-1.
The read_random() function returns the number of bytes placed in buffer.
AUTHORS
Dan Moschuk wrote arc4random().
Mark R V Murray wrote read_random().
BSD September 25, 2000 BSD