LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Remove chars from beginning of line using vi (https://www.linuxquestions.org/questions/linux-general-1/remove-chars-from-beginning-of-line-using-vi-751375/)

Johnomal 08-30-2009 11:18 PM

Remove chars from beginning of line using vi
 
Hi,

I would like to remove n characters from the beginning of all lines in a file using vi.

Can someone please let me know the command to do this?


Thanks,
John

Wim Sturkenboom 08-30-2009 11:40 PM

Not sure of your level of experience.

In command mode, press the colon; next enter the command below and press <enter>
Code:

1,$s/^.\{5}//
where 5 is the number of characters to remove

Johnomal 08-31-2009 01:05 AM

Brilliant.

Thanks, that worked perfectly

Quote:

Originally Posted by Wim Sturkenboom (Post 3663431)
Not sure of your level of experience.

In command mode, press the colon; next enter the command below and press <enter>
Code:

1,$s/^.\{5}//
where 5 is the number of characters to remove


JulianTosh 08-31-2009 01:06 AM

many ways to skin a cat..

in command mode type in the number of characters you'd like to remove, then 'c' for change, then press the space key and then escape.

if you'd like to change the first word, you can use cw for "change word"

catkin 08-31-2009 01:55 AM

Quote:

Originally Posted by Wim Sturkenboom (Post 3663431)
Not sure of your level of experience.

In command mode, press the colon; next enter the command below and press <enter>
Code:

1,$s/^.\{5}//
where 5 is the number of characters to remove

For a slightly shorter version of the same thing, use % as shorthand for 1,$


All times are GMT -5. The time now is 07:45 AM.