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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace data of a file with data from another file using shell scripting.
# 1  
Old 03-08-2013
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:
Code:
00611291,0270404000005453
25262597,1580401000016155
25779812,1700403000001786
00388934,1200408000000880
25522814,7270401000008341
01840654,1860408000000921
. .
. .
. .

I also have another file containing 400,000 records with more or less following format:

Code:
01000101EBP 002     00019356
01000202EBP 002     0120401000000048            985010000019356
01000303EBP 002     0120401000000048            00019356

For example i want to replace 00019356 (from second file) with value 00611291 (from first file).

At the beginning i'm reading a string in specific line with fixed position and fixed length like:

Code:
awk 'NR==2 {print substr($0,21,8)}' TEST_sdi
awk 'NR==3 {print substr($0,21,49),substr($0,56,64)}' TEST_sdi
awk 'NR==4 {print substr($0,165,193),substr($0,195,201)}' TEST_sdi

First problem is, how i can read a string from 400,000 records and second how i can replace those values with values from first file, i suppose sed will do the job but could you please give me some more Smiliedetails.

Many thanks!! Smilie

Last edited by vgersh99; 03-08-2013 at 10:44 AM.. Reason: code tags, please!
# 2  
Old 03-08-2013
assuming the key is the record/line number from each file:
Code:
awk -F,  'FNR==NR{f1[FNR]=$1;next}{$2=f1[FNR]}1' file1 FS=' ' file2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

2. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

3. Shell Programming and Scripting

How to extract data from XML file using shell scripting?

Hi , I have input file as XML. following are input data #complex.xml Code: <?xml version="1.0" encoding="UTF-8"?><TEST_doc xmlns="http://www.w3.org/2001/XMLSchema-instance"> <ENTRY uid="123456"> <protein> <name>PROT001</name> <organism>Human</organism> ... (1 Reply)
Discussion started by: arun_kohan
1 Replies

4. Shell Programming and Scripting

How to extract data from xml file using shell scripting?

Hi evry1, This is my 1st post in this forum.Pls help me I want to extract some data froma xml file which has 2000 lines using shell scripting. Actually my xml file has some "audio and video codes" which i need to arrange in a column wise format after extracting it using shell scripting.I... (4 Replies)
Discussion started by: arun_kohan
4 Replies

5. UNIX for Dummies Questions & Answers

Mapping a data in a file and delete line in source file if data does not exist.

Hi Guys, Please help me with my problem here: I have a source file: 1212 23232 343434 ASAS1 4 3212 23232 343434 ASAS2 4 3234 23232 343434 QWQW1 4 1134 23232 343434 QWQW2 4 3212 23232 343434 QWQW3 4 and a mapping... (4 Replies)
Discussion started by: kokoro
4 Replies

6. Shell Programming and Scripting

Extracting data from file-shell scripting--please help

hello friends, my file is like 123 |asd|asd|asd 123_1|awd|asw|asw 121 |wer|qwe|wee 124 |weq|qwe|iop 1_23 |bla|blh|bha 145 |ghj|jkl|ghj 146 |qwe|qwe|wer 154 |asd|wer|qw_e 134_5|qwe|wer|qw_e is their any solution to retrive only those lines which are having only 3 numerical letters... (20 Replies)
Discussion started by: PankajChawla
20 Replies

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

8. Shell Programming and Scripting

Shell scripting to extract data from file

Hi, i want to fetch the data from the alert log file, for a particular time interval. Example : Alert log content : Thu Mar 18 08:47:36 2010 Completed: alter database open Thu Mar 18 19:13:38 2010 MMNL absent for 6390 secs; Foregrounds taking over Fri Mar 19 08:30:52 2010... (1 Reply)
Discussion started by: Pinki018
1 Replies

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

10. UNIX for Dummies Questions & Answers

How to cut data block from .txt file in shell scripting

Hi All, Currently i have to write a script. For which i need to cut a block from .txt file. I know the specific word that starts the block and ends the block. Can we do it in shell scripting..? Please suggest.... (6 Replies)
Discussion started by: pank29
6 Replies
Login or Register to Ask a Question