Sponsored Content
Top Forums Shell Programming and Scripting Help to replace a field in one file with a field from another file Post 302305440 by savant on Thursday 9th of April 2009 01:28:13 AM
Old 04-09-2009
Thanks ldapswandog..

I tried both the scripts.. the required field is getting replaced with $name/$field2..

For script

for name in $(<temp4); do
nawk -F'|' -v OFS='|' '$2="$name"' temp2 > temp3
done

Files
temp4
gg
re
tt
vv
qq

temp2
11|22|33|44|zz
11|22|33|44|zz
11|22|33|44|zz
11|22|33|44|zz
11|22|33|44|zz


outputf file(temp3)
11|$name|33|44|zz
11|$name|33|44|zz
11|$name|33|44|zz
11|$name|33|44|zz
11|$name|33|44|zz

required output
11|gg|33|44|zz
11|re|33|44|zz
11|tt|33|44|zz
11|vv|33|44|zz
11|qq|33|44|zz


My requirements
===================

file1
11|22|33|44|zz
11|22|33|44|zz
11|22|33|44|zz
11|22|33|44|zz
11|22|33|44|zz


file2
aa|bb|cc1|dd|55
aa|bb|cc2|dd|55
aa|bb|cc3|dd|55
aa|bb|cc4|dd|55
aa|bb|cc5|dd|55


required output
11|22|cc1|44|zz
11|22|cc2|44|zz
11|22|cc3|44|zz
11|22|cc4|44|zz
11|22|cc5|44|zz


I need to replace the 3rd field of file1 with 3rd field of file2 for all records(1st record should be replaced with 1st record only of the other file)
Both files have same number of lines as well as fields.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replace a field in a CSV file

Hello all, I've a CSV file and need to replace 5th field if its value is "X". The exact requirement is to replace 5th field (column) with "Y" if a. it's value is "X" AND b. the line must start with ABC string i guess this can be done with awk. Pl help. For security reasons, the... (2 Replies)
Discussion started by: prvnrk
2 Replies

2. Shell Programming and Scripting

Replace third field of the first record in a file....

Hi, I am new to unix and am trying to do something below: I have a pipe delimited file with millions of records. I need to replace the third column of the first record to the number of lines in the file. How can I do that. Will appreciate any advice and help. Thanks Simi (3 Replies)
Discussion started by: simi28
3 Replies

3. Shell Programming and Scripting

Appending 1st field in a file into 2nd field in another file

Hi, I've internally searched through forums for about 2+ hours. Unfortunately, with no luck. Although I've found some cases close to mine below, but didn't help so much. Actually, I'm in short with time. So I had to post my case. Hoping that you can help. I have 2 files, FILE1 ... (0 Replies)
Discussion started by: amurib
0 Replies

4. Shell Programming and Scripting

Append 1st field from a file into 2nd field of another file

Hi, I've internally searched through forums for about 2+ hours. Unfortunately, with no luck. Although I've found some cases close to mine below, but didn't help so much. Actually, I'm in short with time. So I had to post my case. Hoping that you can help. I have 2 files, FILE1 ... (1 Reply)
Discussion started by: amurib
1 Replies

5. Shell Programming and Scripting

replace blank field in file 2 with content of file 1

Something like vlookup in excel, column 2 in file 2 is blank and should be replaced by column 2 in file 1 based on comparing column 1 in both files. file1 Code: 1234~abc~b~c~d~e~f~g~h~09/10/09 5678~def~b~c~d~e~f~g~h~12/06/10 8910~hij~b~c~d~e~f~g~h~03/28/13... (1 Reply)
Discussion started by: sigh2010
1 Replies

6. Shell Programming and Scripting

Compare two files Field by field and output the result in another file

Hi Friends, Need Help. I have file1.txt as File1.txt |123|A|7267|Hyder|Cross|Sell|7801 |995|A|7051|2008|Lunar|New|Year|Promotion|7801 |996|A|7022|Q108|Targ|Prospect|&|SSCC|Savings|Promo|7801 |997|A|7182|Q1|Feb-Apr|08|Credit|ITA|PA|SBA|Campaign|7801 File2.txt... (7 Replies)
Discussion started by: i150371485
7 Replies

7. Shell Programming and Scripting

Plz Help. Compare 2 files field by field and get the output in another file.

Hi Freinds, I have 2 files . one is source.txt and second one is target.txt. I want to keep source.txt as baseline and compare target.txt. please find the data in 2 files and Expected output. Source.txt 1|HYD|NAG|TRA|34.5|1234 2|CHE|ESW|DES|36.5|134 3|BAN|MEH|TRA|33.5|234... (5 Replies)
Discussion started by: i150371485
5 Replies

8. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

9. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

10. Shell Programming and Scripting

Need to replace last field in a file,if first field matches

Hi, Need to replace last field in a file(/etc/passwd) ,if first filed matches with particular username. Scenario: cat testfor1 deekshi:x:7082:7082::/home/deekshi:/bin/bash harini1:x:7083:7083::/home/harini1:/bin/bash Here,if first field contains "deekshi", then i should replace... (4 Replies)
Discussion started by: Sumanthsv
4 Replies
SoFieldSensor(3)						       Coin							  SoFieldSensor(3)

NAME
SoFieldSensor - The SoFieldSensor class detects changes to a field. Attach a field to a sensor of this type to put it under surveillance, so you can act upon changes to the field. SYNOPSIS
#include <Inventor/sensors/SoFieldSensor.h> Inherits SoDataSensor. Public Member Functions SoFieldSensor (void) SoFieldSensor (SoSensorCB *func, void *data) virtual ~SoFieldSensor (void) void attach (SoField *field) void detach (void) SoField * getAttachedField (void) const virtual void trigger (void) Additional Inherited Members Detailed Description The SoFieldSensor class detects changes to a field. Attach a field to a sensor of this type to put it under surveillance, so you can act upon changes to the field. An SoFieldSensor can also act for delete-callback purposes alone and does not need a regular notification-based callback. Constructor &; Destructor Documentation SoFieldSensor::SoFieldSensor (void) Constructor. SoFieldSensor::SoFieldSensor (SoSensorCB *func, void *data) Constructor taking as parameters the sensor callback function and the userdata which will be passed the callback. See also: setFunction(), setData() SoFieldSensor::~SoFieldSensor (void) [virtual] Destructor. Member Function Documentation void SoFieldSensor::attach (SoField *field) Attach sensor to a field. Whenever the field's value changes, the sensor will be triggered and call the callback function. A field sensor can be attached to only a single field at a time. When this method is invoked multiple times, each subsequent call will replace the field the sensor is monitoring with the new field. When the given field is deleted, the sensor will automatically be detached. See also: detach() void SoFieldSensor::detach (void) Detach sensor from field. As long as an SoFieldSensor is detached, it will never call its callback function. See also: attach() SoField * SoFieldSensor::getAttachedField (void) const Returns a pointer to the field connected to the sensor. See also: attach(), detach() void SoFieldSensor::trigger (void) [virtual] Trigger the sensor's callback function. Reimplemented from SoDataSensor. Author Generated automatically by Doxygen for Coin from the source code. Version 3.1.3 Wed May 23 2012 SoFieldSensor(3)
All times are GMT -4. The time now is 09:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy