-1

I have a file in which the data is like below,

01,0000000,xxxxxxx/                        
02,xxxxxxxx,yyyyyy/                                    
03,test1,41203016,,/      
01,0000000,xxxxxxx/                        
02,xxxxxxxx,yyyyyy/                                    
03,test2,41203017,,/     
01,0000000,xxxxxxx/                        
02,xxxxxxxx,yyyyyy/                                    
03,test3,41203018,,/    

I will not be knowing what values will be there In the file for test1,test2 and test3. I know that it will be in the line starting with 03 and also I have to dynamically derive the replace strings based on test string.

Is there a way to do this in unix? Is yes, please provide the command.

  • Find-replace actions are very common in the *nix world. What have you tried? A simple google search for your title reveals many sites that can help you answer your question. Guidelines on how to ask questions on U&L are here: http://unix.stackexchange.com/help/how-to-ask . – KM. Apr 08 '15 at 17:20

1 Answers1

0

A previous comment said that this maybe a too common a question for this forum. And you probably need to research common stream editing.

But just as a quick answer, try something like this.

sed -i -e 's/test1/replace1/g' -e 's/test2/replace2/g' [...] Filename
Anthon
  • 79,293
Cosmo F
  • 169
  • This is a Q&A site, not a forum – Anthon Apr 08 '15 at 17:46
  • Thanks for your answer. I came accross this answer in google. But this not the scenario I have. I will not be knowing what values will be there In the file for test1,test2 and test3. I know that this will be in the line starting with 03 and also I have to dynamically drive the replace strings based on test string. – LearnOracle Apr 08 '15 at 17:46