Operating System - HP-UX
1753519 Members
4828 Online
108795 Solutions
New Discussion юеВ

Replace a field in a file.

 
Muktha
Frequent Advisor

Replace a field in a file.

Hi all,

I need to replace a field of a line with another pattern.The field can be empty also.
There are 2 files file1 and file2.
By refering file2 , I need to replace 5th column of file1 .
I can replace if the field is not empty .But when its emtpy ,I am finding difficulty to replace as there can be other fields also empty.So I need to replace according to the position.

Could you please help me to resolve this.

Regards
Muktha
3 REPLIES 3
James R. Ferguson
Acclaimed Contributor

Re: Replace a field in a file.

Hi:

Posting samples of your input file(s) and the desired output would help answer your question.

...JRF...
Rita C Workman
Honored Contributor

Re: Replace a field in a file.

Not alot of info here, but....

You could use the 'join' command and take the fields you want from file 1 or f2 (in any order) and then send the output to a new file.

It has options not only to create a new file with the fields in any order, but it also has the -e option that might be beneficial to you.

man join

Rgrds,
Rita
rmueller58
Valued Contributor

Re: Replace a field in a file.

I went through something similar a while back.. See this thread.


https://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1375335