Sponsored Content
Top Forums Shell Programming and Scripting Replace a value using a reference data from other file Post 302926699 by jiam912 on Wednesday 26th of November 2014 08:05:25 AM
Old 11-26-2014
Dear XL
Thanks a lot for your script works fine.
But please can you change it to let it works even if the original_file.txt and the input file have different location when it finds the value =2 in column 49

Input file
Example

Code:
X  4708      3010  69523.00  19321.001    1  1461  69524.00  19254.00  19544.001
X  4708      3010  69523.00  19321.001  147  2761  69536.00  19286.00  19544.001
X  4708      3010  69523.00  19321.001  277  3921  69548.00  19314.00  19544.001
X  4708      3010  69523.00  19321.001  393  4921  69560.00  19346.00  19544.001
X  4708      3010  69523.00  19321.001  493  5571  69572.00  19416.00  19544.001
X  4708      3010  69523.00  19321.001  558  6101  69584.00  19440.00  19544.001
X  4708      3010  69523.00  19321.001  611  6531  69596.00  19460.00  19544.001
X  4708      3010  69523.00  19321.001  654  6861  69608.00  19480.00  19544.001
X  4708      3010  69523.00  19321.001  687  7111  69620.00  19496.00  19544.001
X  4708      3010  69523.00  19321.001  712  7281  69632.00  19512.00  19544.001
X  4708      3010  69523.00  19321.001  729  7391  69644.00  19524.00  19544.001
X  4708      3110  69523.00  19353.001    1  1621  69524.00  19254.00  19576.001
X  4708      3110  69523.00  19353.001  163  3081  69536.00  19286.00  19576.001
X  4708      3110  69523.00  19353.001  309  4401  69548.00  19314.00  19576.001
X  4708      3110  69523.00  19353.001  441  5561  69560.00  19346.00  19576.001
X  4708      3110  69523.00  19353.001  557  6371  69572.00  19416.00  19576.001
X  4708      3110  69523.00  19353.001  638  7061  69584.00  19440.00  19576.001
X  4708      3110  69523.00  19353.001  707  7651  69596.00  19460.00  19576.001
X  4708      3110  69523.00  19353.001  766  8141  69608.00  19480.00  19576.001
X  4708      3110  69523.00  19353.001  815  8551  69620.00  19496.00  19576.001
X  4708      3110  69523.00  19353.001  856  8881  69632.00  19512.00  19576.001
X  4708      3110  69523.00  19353.001  889  9151  69644.00  19524.00  19576.001
X  4708      3110  69523.00  19353.001  916  9311  69656.00  19546.00  19576.001
X  4708      3110  69523.00  19353.001  932  9331  69668.00  19572.00  19574.001
X  4708      3110  69523.00  19353.001  934  9352  69668.00  19576.00  19576.001

original_file.txt
Code:
X                  69523.00  19353.001    1  1621  69524.00  19254.00  19576.001
X                  69523.00  19353.001  163  3081  69536.00  19286.00  19576.001
X                  69523.00  19353.001  309  4401  69548.00  19314.00  19576.001
X                  69523.00  19353.001  441  5561  69560.00  19346.00  19576.001
X                  69523.00  19353.001  557  6371  69572.00  19416.00  19576.001
X                  69523.00  19353.001  638  7061  69584.00  19440.00  19576.001
X                  69523.00  19353.001  707  7651  69596.00  19460.00  19576.001
X                  69523.00  19353.001  766  8141  69608.00  19480.00  19576.001
X                  69523.00  19353.001  815  8551  69620.00  19496.00  19576.001
X                  69523.00  19353.001  856  8881  69632.00  19512.00  19576.001
X                  69523.00  19353.001  889  9151  69644.00  19524.00  19576.001
X                  69523.00  19353.001  916  9311  69656.00  19546.00  19576.001
X                  69523.00  19353.001  932  9341  69668.00  19572.00  19576.001
X                  69523.00  19353.001  935  9351  69680.00  19576.00  19576.001

The key is to find the match the key substr($0,20,18).

Hope you can help me. I have tested it and works fine but needs to have the values to compare exactly in the same row in both files but sometimes I have more data can be in original or input files and the script give other information.

Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find and replace data in text file with data in same file

OK I will do my best to explain what I need help with. I am trying to format an ldif file so I can import it into Oracle oid. I need the file to look like this example. Keep in mind there are 3000 of these in the file. changetype: modify replace: userpassword dn:... (0 Replies)
Discussion started by: timothyha22
0 Replies

2. Shell Programming and Scripting

Replace character based on reference file problem asking

I got two files right now, input file (target file), reference file 1 (query file) reference file 1 (long list of data) KOLOPWMOPOPO ADASDASD ADSASDASDAD . . target file (one long liner content) ADASDASDTYUKOKOLOPWMOPOPOOPLUAADSASDASDADPOPOUYADADASDASD desired output file content ... (1 Reply)
Discussion started by: patrick87
1 Replies

3. Shell Programming and Scripting

Replace data of one column with data on other file corresponding to transaction ID matched

Hi All, I have two files one of which having some mobile numbers and corresponding value whose sample content as follows: 9058629605,8.0 9122828964,30.0 And in second file complete details of all mobile numbers and sample content as follows and delimeter used is comma(,): ... (8 Replies)
Discussion started by: poweroflinux
8 Replies

4. Shell Programming and Scripting

Help with replace column one content based on reference file

Input file 1 testing 10 20 1 A testing 20 40 1 3 testing 23 232 2 1 testing 10 243 2 . . Reference file 1 final 3 used . . Output file (2 Replies)
Discussion started by: perl_beginner
2 Replies

5. Shell Programming and Scripting

Help with replace column one content based on reference file

Input file 1 testing 10 20 1 A testing 20 40 1 3 testing 23 232 2 1 testing 10 243 2 . . Reference file 1 final 3 used . . Output file (1 Reply)
Discussion started by: perl_beginner
1 Replies

6. Shell Programming and Scripting

Replace data of a file with data from another file using shell scripting.

Dears, I'm new to shell scripting and i was wondering if you can help me with following matter. I have a file containing 400,000 records. The file contains two columns like: 00611291,0270404000005453 25262597,1580401000016155 25779812,1700403000001786 00388934,1200408000000880... (1 Reply)
Discussion started by: paniklas
1 Replies

7. Shell Programming and Scripting

[Solved] Replace records according to reference

Dear All, I am struggling with the following task and would appreciate some help. I have a large table (file1.txt). The first column of this table contains an ID. I would like to replace the ID with a label according to a reference file. Here is an example: cat infile.txt 0 AJ2312 310 ... (7 Replies)
Discussion started by: GDC
7 Replies

8. Shell Programming and Scripting

Replace from reference file awk

Basically want to replace any field in input file from the refernce file ... for example. clar_2400:3113 in input file will be replaced by clar_2400:3113 Input file field seperator is "," Field which is not found in reference will stay as it is ... Input File ... (3 Replies)
Discussion started by: greycells
3 Replies

9. Shell Programming and Scripting

Compare data with reference from other file

Gents, Please can you help with this. I have a big file (file2) which contends many records increment every 25 rows ( column 1 ). Then I have other file as reference (file1).. column 1 to 11. I want to compare that all values in file2 (column 2 to 12.) match with values in... (2 Replies)
Discussion started by: jiam912
2 Replies

10. UNIX for Dummies Questions & Answers

awk to replace values in one file using a second reference file

Hi, I'd be grateful for your help with the following: I have a file with a single column (file1). Let's say the values are: a b c 5 d I have a second, reference file (ref_file), which is colon-delimited, and is effectively a key. Let's say the values in it are: a:1 b:2 c:3 d:4... (4 Replies)
Discussion started by: aberg
4 Replies
HISTO(1)						      General Commands Manual							  HISTO(1)

NAME
histo - compute 1-dimensional histogram of N data columns SYNOPSIS
histo [-c][-p] xmin xmax nbins histo [-c][-p] imin imax DESCRIPTION
Histo bins columnular data on the standard input between the given minimum and maximum values. If three command line arguments are given, the third is taken as the number of data bins between the first two real numbers. If only two arguments are given, they are both assumed to be integers, and the number of data bins will be equal to their difference plus one. The bins are always of equal size. The output is N+1 columns of data (for N columns input), where the first column is the centroid of each division, and each row corresponds to the frequencies for each column around that value. If the -c option is present, then histo computes the cumulative histogram for each column instead of the straight frequencies. The upper value of each bin is printed also instead of the centroid. This may be useful in computing percentiles, for example. Values below the minimum specified are still counted in the cumulative total. The -p option tells histo to report the percentage of the total number of input lines rather than the absolute counts. In the case of a cumulative total, this yields the percentile values directly. Values above the maximum are counted as well as values below in this case. All input data is interpreted as real values, and columns must be white-space separated. If any value is less than the minimum or greater than the maximum, it will be ignored unless the -c option is specified. EXAMPLE
To count data values between -1 and 1 in 50 bins: histo -1 1 50 < input.dat To count frequencies of integers between 0 and 255: histo 0 255 < input.dat AUTHOR
Greg Ward SEE ALSO
cnt(1), neaten(1), rcalc(1), rlam(1), tabfunc(1), total(1) RADIANCE
9/6/96 HISTO(1)
All times are GMT -4. The time now is 05:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy