Home » Software Development » Editor » Vim » How to delete first few characters in each line in a text file using VI ?

How to delete first few characters in each line in a text file using VI ?

In a Linux kernel development, many times we need to check the kernel booting messages using “dmesg” command, and if we need to compare two dmesg logs captured in two text files, it becomes difficult to identify the real change in logs because “dmesg” adds the timestamp at the beginning of every log.

[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x51af8014]

So, even if we have same log in dmesg, we see difference because of added timestamp. So to properly compare two dmesg logs, we need to delete the first 15 characters from every line i.e. “[ 0.000000] ” string..

this can be done using vim option,

:%s/^.\{0,15\}//g

Note, here we have added “15” number to delete first 15 characters of every line. You can change this number as you required.


Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment