Sponsored Content
Top Forums Shell Programming and Scripting Replace a value using a reference data from other file Post 302926477 by jiam912 on Monday 24th of November 2014 04:08:43 PM
Old 11-24-2014
Replace a value using a reference data from other file

Gents,

Can you please help me to solve this case

In my input file I have a values in column 49 which always need to be one, but sometimes the system create a value 2, in this case I need to go to search in the original file and replace the values in the row where the value 2 is and in the previous.

Example input file

Code:
X  4708      3310  69521.00  19353.001  932  9331  69668.00  19572.00  19574.001
X  4708      3310  69521.00  19353.001  934  9352  69668.00  19576.00  19576.001

The situation is when the value in column 49 changes to value = 2, then I need to change some values in row where it is value 2 and previous row.

changes need to be done in previous row , column 46 , 72
next row , column 41, 49, 52
using the values in original file.

Values in original file

Code:
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

Desire output file
Code:
X  4708      3110  69523.00  19353.001  932  9341  69668.00  19572.00  19576.001
X  4708      3110  69523.00  19353.001  935  9351  69680.00  19576.00  19576.001x

Files attached , hope can help me.Smilie

I have started to see how I can get it

Code:
awk '{if(/^X/)print $0}' input.txt | awk '{\
	 ln = substr($0,20,5);\
	 vp = substr($0,30,5);\
	 rpl = substr($0,52,5);\
	 flc = substr($0,40,9);\
	 tc = ((substr($0,45,4)- substr($0,40,4))+1);\
	 if (tc == 1) {\
			printf ("Point : %5d/%5d in RL %5d has %4d channels in swath %4d\n", ln,vp,rpl,tc,1000 )}}' > tmpab$swath

 

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
All times are GMT -4. The time now is 08:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy