Monday, April 18, 2016

Modifying file using Vim and awk

In some case, we have to change a big file with the same type of text. We can use vim editor for doing this type of task. Suppose, we have a files as below:


Now for a need, we need to generate delete script from this file contents as below:


For doing so, 

1. we have opened the file using vim editor. vim loglistws.txt
2.Then we have used the below commnads to add double quate around the words : 
   :%s/EJB_Str/"EJB_Str/g
   
Then save the file using :w
   :%s/\.log/\.log"/g

3. Now save the file using :wq!
4. Now we have made a new file form the existing file as:
    cat loglistws.txt | awk '{print "rm ",$9,$10,$11,$12}' > myscriptws.sh

No comments: