How to insert gaussian noise to a data with an order with awk?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to insert gaussian noise to a data with an order with awk?
# 8  
Old 07-23-2012
The process is all the way same to the end of the file until all the noise numbers will be added to all the times after station names... And the lines with 0 0.000 will stay the same
# 9  
Old 07-23-2012
I mean, does it start over with the first value from the second file or does it continue with the 7th value?
# 10  
Old 07-23-2012
Ohh yes it must be continue with the 7th number till, for example 11000th number...
# 11  
Old 07-23-2012
Something like this?
Code:
awk '
  {
    for(i=1;i<=NF;i++)                                    # for every field on every line
      if($i~/[A-Z]{5}[0-9]$/){                            # if a field contains a station number
        getline p<f                                       # then get the next noise correction
        split(p,N)                                        # split the fields of the noise correction into array N
        sub($(i+1)+0,sprintf("%.3f",$(i+1)+N[2]),$(i+1))  # substitute the numerical value in the next field with the modified value
      }
  }
  1                                                       # print line
' f=noise data                                            # set variable f to noise file

noise and data are arbitrary file names



--
if you are using gawk, use gawk --posix
This wil not work with mawk
On Solaris use /usr/xpg4/bin/awk

Last edited by Scrutinizer; 07-23-2012 at 09:36 AM..
# 12  
Old 07-23-2012
I see that it is a little bit complicated I could not understand what is "p" for and when I run the script:


Code:
  sezim@localhost#cat gauss.awk
 awk '   {     for(i=1;i<=NF;i++)                                    # for every field on every line       
 if($i~/[A-Z]{5}[0-9]$/){                                                 # if a field contains a station number         
 getline p<f                                                                     # then get the next noise correction         
 split(p,N)                                                                        # split the fields of the noise correction into array N  sub($(i+1)+0,sprintf("%.3f",$(i+1)+N[2]),$(i+1))          # substitute the numerical value in the next field with the modified value       }   
}   
1                                                                                       # print line 
' f=noisedata                                                                    # set variable f to noise file 

sezim@localhost#awk -f gauss.awk mydata 
awk: gauss.awk:1: awk ' 
awk: gauss.awk:1:     ^ invalid char ''' in expression

Is it some kind of expression problem?
# 13  
Old 07-23-2012
p is just a variable name. If you want to put it in a script then try leaving out awk and the quotes:

Code:
{
  for(i=1;i<=NF;i++)                                    # for every field on every line
    if($i~/[A-Z]{5}[0-9]$/){                            # if a field contains a station number
      getline p<f                                       # then get the next noise correction
      split(p,N)                                        # split the fields of the noise correction
      sub($(i+1)+0,sprintf("%.3f",$(i+1)+N[2]),$(i+1))  # substitute the numerical value in the next field with the modified value
    }
}
1                                                       # print line

Then try calling it like:
Code:
awk -f gauss.awk f=noisedata mydata

# 14  
Old 07-23-2012
Thank you very much my friend I know it will work but it gives an error again:

Code:
sezim@localhost#awk -f gauss.awk f=noisedata mydata
awk: gauss.awk:2:   for(=1;i<=NF;i++)                                    # for every field on every line
awk: gauss.awk:2:       ^ syntax error
awk: gauss.awk:2:   for(=1;i<=NF;i++)                                    # for every field on every line
awk: gauss.awk:2:

Is it because of the number of the noise numbers?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question