LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 03-30-2007, 01:31 PM   #1
RobHill
LQ Newbie
 
Registered: Mar 2007
Posts: 7

Rep: Reputation: 0
vi question regarding removing part of a line


What command can I use to delete everything from the beginning of a line up to a specific word in the line? Let me add to that, I want to do it for an entire file, not just a fe lines in the file.

Last edited by RobHill; 03-30-2007 at 01:45 PM.
 
Old 03-30-2007, 01:35 PM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,028
Blog Entries: 5

Rep: Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791
If you knew how many "words" there were you could do #dw where # is the number of words before what you want to delete.

e.g.
"The quick brown fox jumped over the lazy dog"

From start of line 5dw would leave you with:
"over the lazy dog"

It gets tricky sometimes figuring out what a "word" is. Usually it is items separated by white space however some characters are treated as words.

e.g.
The quick brown (fox) jumped over the lazy dog

From start of line 5dw would leave you with:
") jumped over the lazy dog"
because it counted the "(" as a "word".
 
Old 03-30-2007, 03:42 PM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,523

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
Try that one, assuming the word is "foo" and you want to keep it:
Code:
:% s/^.*\<foo\>/foo/

Last edited by jlliagre; 03-30-2007 at 03:44 PM.
 
  


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sed and printing only part of a line jrdioko Linux - Software 12 05-17-2012 08:15 PM
shell script question: removing a line according to a duplicate "field" mattie_linux Linux - Newbie 1 01-12-2006 04:57 PM
Regex Question: Only print part of line that matches TheMeteorPolice Programming 5 01-12-2006 02:21 PM
part of line disappears when scrolling in Mozilla andrewstr Linux - Software 4 11-05-2003 07:38 PM
How to extract a part of a line by sed? J_Szucs Programming 2 02-15-2003 07:49 PM


All times are GMT -5. The time now is 10:23 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration