LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-30-2009, 11:18 PM   #1
Johnomal
LQ Newbie
 
Registered: Aug 2009
Posts: 6

Rep: Reputation: 0
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
 
Old 08-30-2009, 11:40 PM   #2
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
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

Last edited by Wim Sturkenboom; 08-30-2009 at 11:49 PM.
 
Old 08-31-2009, 01:05 AM   #3
Johnomal
LQ Newbie
 
Registered: Aug 2009
Posts: 6

Original Poster
Rep: Reputation: 0
Brilliant.

Thanks, that worked perfectly

Quote:
Originally Posted by Wim Sturkenboom View Post
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
 
Old 08-31-2009, 01:06 AM   #4
JulianTosh
Member
 
Registered: Sep 2007
Location: Las Vegas, NV
Distribution: Fedora / CentOS
Posts: 674
Blog Entries: 3

Rep: Reputation: 90
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"
 
Old 08-31-2009, 01:55 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196
Quote:
Originally Posted by Wim Sturkenboom View Post
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,$
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl question: delete line from text file with duplicate match at beginning of line mrealty Programming 7 04-01-2009 06:46 PM
display only certain chars in each line cranium2004 Programming 2 02-21-2006 02:03 PM
how many chars can be displayed in a line? williamjxj Linux - Software 1 10-25-2004 03:24 AM
PHP-Remove multiple chars Boby Programming 1 10-01-2004 08:34 PM
How to remove or strip control chars in the 'script' utility? fieldmethods Linux - General 1 10-24-2003 01:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration