-1

This question already has an answer here:

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.

marked as duplicate by don_crissti, Anthon, Costas, derobert, Karlson Apr 8 '15 at 18:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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: unix.stackexchange.com/help/how-to-ask . – KM. Apr 8 '15 at 17:20
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
  • This is a Q&A site, not a forum – Anthon Apr 8 '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 8 '15 at 17:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.