Sponsored Content
Top Forums Shell Programming and Scripting How to insert gaussian noise to a data with an order with awk? Post 302676065 by raj_saini20 on Tuesday 24th of July 2012 03:56:30 AM
Old 07-24-2012
Try this (tested in hp-ux)

Code:
$awk 'BEGIN{f1=0;i=1;k=1;while (getline < "file2"){a[i++]=$2}}
{if($1 ~ /^[A-Z]/){l=length($0);for(j=1;j<=l;j=j+6){val=substr($0,j,6);if(val ~ /^[A-Z]/){f1=1;printf val}else{if(f1==1){s=substr($0,j,6);gsub(" ","",s);f1=0;sm=s+a[k];k++;printf "%6.3f",sm}else{printf val}}};printf "\n"}
else{print}}' file1

and output is
Code:
0910 1 2048 32.38 40 20.88  28 35.53  9.62  0.00
MSDMP0 1.804MSDMS1 2.869KCTXP2 4.384KRCMP0 4.506BOZMP0 5.609BOZMS2 9.378
ARMTP2 6.611ARMTS211.582FRR6P0 8.297FRR6S014.046CINRP0 8.842FRR7P0 8.560
FRR7S015.376TRNMP013.088CEKMP016.103ATIMP216.153KRBGP319.275     0 0.000
     0 0.000     0 0.000     0 0.000     0 0.000     0 0.000     0 0.000
0910 1 2328 55.48 40 40.72  29 13.24  8.31  0.00
KLCMP0 3.432KLCMS1 5.981SAKIP0 3.837SAKIS1 6.378ARCEP0 4.149ARCES1 6.837
GBZMP0 4.496GBZMS2 7.617IBBTP0 4.643IBBTS2 7.878BUYMP0 4.610BUYMS2 7.680
GOZTP0 4.860GOZTS2 8.140CINRP0 4.000KRMLP0 5.110KRMLS0 8.020SABAP0 5.290
SABAS2 8.950ESKMP0 5.220ESKMS2 9.040GEMTP2 5.220MOLLP0 6.140MOLLS0 9.680
KURNP0 6.140KURNS210.270FRONP0 5.770ARMTP2 6.320ARMTS210.820CEKMP0 7.320
CEKMS012.720FRR7P0 7.160BOZMP0 7.680BOZMS313.180ISK P2 7.320ISK S212.720
IGDMP0 8.570IGDMS214.410MDNYP2 8.360ADVTP2 8.840FRR6P010.680FRR6S018.000
SILTP210.020KLYTP211.180MSDMP011.360MSDMS219.970BGKTP210.790ELBAP014.820
CTKSP313.910KCTXP315.860KRCMP115.720SNLMP118.520SNLMS232.140SLVTP317.020
TRNMP121.250GONEP324.790KRBGP326.340RKY P327.110LAP P332.180     0 0.000
     0 0.000     0 0.000     0 0.000     0 0.000     0 0.000     0 0.000
0910 2 20 9 50.48 40 34.52  28 54.61 14.09  0.00
ARMTP2 2.140ARMTS2 4.220ESKMP0 2.680ESKMS1 4.400CINRP0 3.180BOZMP0 3.500
BOZMS2 5.570MDNYP2 5.180FRR7P0 4.790FRR7S0 8.640GEMTP2 5.790FRONP0 6.000
FRR6P0 6.610BUYMP0 7.070BUYMS211.790MSDMP0 7.250MSDMS212.140IBBTP0 8.500
IBBTS214.860KLCMP0 7.860IGDMP0 8.220IGDMS213.680SABAP0 9.640SABAS216.520
KURNP010.000KURNS216.820ISK P3 8.820KCTXP310.250KRCMP010.790KRCMS219.360
MOLLP010.640KLYTP311.900TRNMP016.570     0 0.000     0 0.000     0 0.000
     0 0.000     0 0.000     0 0.000     0 0.000     0 0.000     0 0.000

This User Gave Thanks to raj_saini20 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK - printing certain fields when field order changes in data file

I'm hoping someone can help me on this. I have a data file that greatly simplified might look like this: sec;src;dst;proto 421;10.10.10.1;10.10.10.2;tcp 426;10.10.10.3;10.10.10.4;udp 442;10.10.10.5;10.10.10.6;tcp sec;src;fac;dst;proto 521;10.10.10.1;ab;10.10.10.2;tcp... (3 Replies)
Discussion started by: eric4
3 Replies

2. Solaris

Not able to insert data

Hi All, I enhanced a perl script that creates a table with xyz_yyyymm and insert data from xyz table before truncate xyz.I have tested it successfully in dev but when i ran it on production new table xyz_yyyymm created but did not insert any records from xyz.(No errors were thrown)The perl... (1 Reply)
Discussion started by: megh
1 Replies

3. Shell Programming and Scripting

How to insert data befor some field in a row of data depending up on values in row

Hi I need to do some thing like "find and insert before that " in a file which contains many records. This will be clear with the following example. The original data record should be some thing like this 60119827 RTMS_LOCATION_CDR INSTANT_POSITION_QUERY 1236574686123083rtmssrv7 ... (8 Replies)
Discussion started by: aemunathan
8 Replies

4. Shell Programming and Scripting

Awk: Data Insert

Hi guys, I'm having some difficulties in insert some details to the following contents. I need to insert "TEST" under MIR & a value "25" to the next line. So far, I am able to insert "TEST" by using awk to capture MIR as the identifier. However, I am having some difficulties in inserting "25"... (3 Replies)
Discussion started by: nantheless
3 Replies

5. Shell Programming and Scripting

Generating Gaussian Distributed Random Numbers

I want to generate an awk function that generated a Gaussian distributed set of random numbers. I need to implement the thing below in awk. Rnd is just a uniform random number between 0 and 1 function rgaussian(r1, r2) { Do v1 = 2 * Rnd - 1 v2 = 2 * Rnd - 1 ... (0 Replies)
Discussion started by: kristinu
0 Replies

6. Shell Programming and Scripting

Help with sort data based on descending order problem

Input file 9.99331e-13 8.98451e-65 9.98418e-34 7.98319e-08 365592 111669 74942.9 0 Desired output 365592 111669 74942.9 7.98319e-08 1.99331e-13 6.98418e-34 (2 Replies)
Discussion started by: perl_beginner
2 Replies

7. Shell Programming and Scripting

how to extract data from numbered files using linux in the numerical order-

Hi experts, I have a list of files containing forces as the only number as follows. Force1.txt Force2.txt Force3.txt Force4.txt Force5.txt . . . . . . . . . Force100.txt I want to put all the data(only a number ) in these forces files in the file with the same order like 1,2,3 ..100 .... (2 Replies)
Discussion started by: hamnsan
2 Replies

8. Shell Programming and Scripting

Parsing XML (and insert data) then output data (bash / Solaris)

Hi folks I have a script I wrote that basically parses a bunch of config and xml files works out were to add in the new content then spits out the data into a new file. It all works - apart from the xml and config file format in the new file with XML files the original XML (that ends up in... (2 Replies)
Discussion started by: dfinch
2 Replies

9. Shell Programming and Scripting

How order a data matrix using awk?

is it possible to order the following row clusters from ascending to descending. thanx in advance input 1 2 4 0 1 2 4 0 3 3 3 3 1 5 1 0 1 5 1 0 6 0 0 0 5 1 1 1... (4 Replies)
Discussion started by: quincyjones
4 Replies

10. Shell Programming and Scripting

Order of data in Spool File

Hello, I have a shell script through which I am executing .sql file and spooling the result of Query from .sql . I want to spool the result in ascending order. Is there any parameter to be set to print result in ascending or descending order. Thanks in advance. (4 Replies)
Discussion started by: Aparna.N
4 Replies
GETLINE(3)						     Linux Programmer's Manual							GETLINE(3)

NAME
getline, getdelim - delimited string input SYNOPSIS
#define _GNU_SOURCE #include <stdio.h> ssize_t getline(char **lineptr, size_t *n, FILE *stream); ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream); DESCRIPTION
getline() reads an entire line, storing the address of the buffer containing the text into *lineptr. The buffer is null-terminated and includes the newline character, if a newline delimiter was found. If *lineptr is NULL, the getline() routine will allocate a buffer for containing the line, which must be freed by the user program. Alter- natively, before calling getline(), *lineptr can contain a pointer to a malloc()-allocated buffer *n bytes in size. If the buffer is not large enough to hold the line read in, getline() resizes the buffer to fit with realloc(), updating *lineptr and *n as necessary. In either case, on a successful call, *lineptr and *n will be updated to reflect the buffer address and size respectively. getdelim() works like getline(), except a line delimiter other than newline can be specified as the delimiter argument. As with getline(), a delimiter character is not added if one was not present in the input before end of file was reached. RETURN VALUE
On success, getline() and getdelim() return the number of characters read, including the delimiter character, but not including the termi- nating null character. This value can be used to handle embedded null characters in the line read. Both functions return -1 on failure to read a line (including end of file condition). ERRORS
EINVAL Bad parameters (n or lineptr is NULL, or stream is not valid). EXAMPLE
#define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> int main(void) { FILE * fp; char * line = NULL; size_t len = 0; ssize_t read; fp = fopen("/etc/motd", "r"); if (fp == NULL) exit(EXIT_FAILURE); while ((read = getline(&line, &len, fp)) != -1) { printf("Retrieved line of length %zu : ", read); printf("%s", line); } if (line) free(line); return EXIT_SUCCESS; } CONFORMING TO
Both getline() and getdelim() are GNU extensions. They are available since libc 4.6.27. SEE ALSO
read(2), fopen(3), fread(3), gets(3), fgets(3), scanf(3) GNU
2001-10-07 GETLINE(3)
All times are GMT -4. The time now is 11:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy