The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
To read and separate number and words in file and store to two new file using shell kamakshi s Shell Programming and Scripting 2 06-26-2008 08:39 AM
Delete words in File 1 from File 2 Enobarbus37 Shell Programming and Scripting 14 02-15-2008 08:09 AM
sed [delete everything between two words] Orbix UNIX for Dummies Questions & Answers 3 12-25-2007 08:27 AM
Delete lines that contain 3 or more words? revax Shell Programming and Scripting 5 12-11-2007 06:33 PM
sed option to delete two words within a file klannon UNIX for Dummies Questions & Answers 4 04-15-2002 08:25 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 4.00 average. Display Modes
  #1 (permalink)  
Old 10-27-2008
sentak sentak is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 13
How to delete first 10 words from file

Hi,

Could you please let me know, how to delete first 10 words from text files using vi?

10dw will delete it from current line, how to do it for all the lines from file?

Thanks
  #2 (permalink)  
Old 10-27-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,886
Use Perl:

Code:
perl -i~ -0pe's/(\w+\s+)/++$c<11?"":$1/ge' infile

With vi (in visual mode):

Code:
d10W

Last edited by radoulov; 10-28-2008 at 03:57 PM.. Reason: 11 -> 10
  #3 (permalink)  
Old 10-27-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink Here is a way before putting into vi

> cat file02
1 2 3 4 5 6 7 8 9 10 11 12
a b c dd eee f g hhh i jjjj kk lllll mm nn oo ppppp
aaaa b ccc d ee ff gg hhh i j kkkk ll mm nnnn o p qq
> cut -d" " -f11- file02
11 12
kk lllll mm nn oo ppppp
kkkk ll mm nnnn o p qq
  #4 (permalink)  
Old 10-28-2008
spirtle spirtle is offline
Registered User
  
 

Join Date: Jun 2008
Location: Scotland
Posts: 150
If your words are separated by arbitrary numbers of white-space characters or the lines can begin with spaces, you could use
Code:
perl -n -e 'split; print "@_[10..$#_]\n"' file
although this does not preserve whitespace between the remaining words that get printed.
  #5 (permalink)  
Old 10-28-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,930
vi has no way of doing what you want to do using a standard builtin command. However you can call an external utility such as awk from within vi using the ":" command as shown in the following example
Code:
:1,$ !awk '{ for (i=11;i<=NF;i++) printf "\%s ", $i; printf "\n"; }'
Note the space between the "$" and "!" and the '\" in front of "%s" in the awk printf statement. Without the slash the word "files" is outputted instead of the expected field text.

Suppose we have the following file:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 line1
line2

a b c d e f g h i j k l m n line4
the following is the file contents after executing the above command
Code:
11 12 13 line1 


k l m n line4

Last edited by fpmurphy; 10-28-2008 at 01:40 PM.. Reason: f
  #6 (permalink)  
Old 10-28-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,886
Quote:
vi has no way of doing what you want to do using a standard builtin command [...]
Just curious: isn't my second solution working for you?

P.S. I've just corrected it: 10 instead of 11.

Reading the vi help pages: perhaps d10E is even more correct.

Last edited by radoulov; 10-28-2008 at 04:07 PM..
  #7 (permalink)  
Old 10-29-2008
migurus migurus is offline
Registered User
  
 

Join Date: Sep 2008
Location: US
Posts: 49
this will not work in stock vi, but in vim you could say this:

Code:
:%s/\(\<\w\+\>\s\+\)\{10}//
to remove first 10 words throughout the whole file
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:24 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0