The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Use wildcards in a script emferrari Shell Programming and Scripting 13 03-07-2008 04:14 AM
wildcards NOT C3000 UNIX for Dummies Questions & Answers 5 11-21-2007 07:19 AM
Wildcards in SED HealthyGuy Shell Programming and Scripting 5 09-27-2006 08:32 PM
ls with wildcards benu302000 UNIX for Dummies Questions & Answers 10 06-29-2005 02:53 PM
wildcards benu302000 UNIX for Dummies Questions & Answers 3 06-29-2005 01:10 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 Rate Thread Display Modes
  #1 (permalink)  
Old 01-03-2002
peter.herlihy peter.herlihy is offline
Registered User
  
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
Angry Wildcards in VI

I'm trying to delete lines from a large text file using VI.
Every line that I am wanting to delete start with 'S' - all others do not. (A list of users)

I've tried using * but doesn't seem to like it...any ideas...

Doesn't have to be VI - but I'm better with VI than sed/awk.
  #2 (permalink)  
Old 01-03-2002
peter.herlihy peter.herlihy is offline
Registered User
  
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
Ah...ooops...there are some that do start with S....

But all those that start with S[0-9] should be removed - those that start S[A-Z] should remain.

Also another way might be looking for any rows with [0-9] appearing in them anywhere - as these too will satisfy the criteria.

.....

  #3 (permalink)  
Old 01-03-2002
auswipe's Avatar
auswipe auswipe is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Wide Awake Wylie, Texas
Posts: 535
Quote:
Originally posted by peter.herlihy
Ah...ooops...there are some that do start with S....

But all those that start with S[0-9] should be removed - those that start S[A-Z] should remain.

Also another way might be looking for any rows with [0-9] appearing in them anywhere - as these too will satisfy the criteria.

.....

I couldn't find any simple way of a mass deletion in vi using a regexp, but I am sure that somebody out there has that knowledge...

How about using :

Code:
grep -v "^S[0-9].*" oldfile > newfile
The file, newfile will be devoid of entries that start with S[0-9].

I use `grep -v` all the time to remove undesired entries from logfiles and it normally works like a champ.
  #4 (permalink)  
Old 01-03-2002
auswipe's Avatar
auswipe auswipe is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Wide Awake Wylie, Texas
Posts: 535
D'oh!

I saw this message in another thread from J.P.:

Quote:
Originally posted by J.P
You can also use this command in Elvis, it should work in Vi too probably

:g/^$/d

This deletes all blank lines

/
JP
You can use :g/^S[0-9].*/d to perform the mass deletion in vi. I thought there was a way to do it but couldn't remember /g, only %s for mass subsitutions!
  #5 (permalink)  
Old 01-04-2002
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Quote:
Also another way might be looking for any rows with [0-9] appearing in them anywhere - as these too will satisfy the criteria.
Well, if you're looking for anything with numbers in the name ([0-9]), why bother looking for line beginning with S AND having a number in it? Why not simply remove any line with a number in it?

:g/.*[0-9].*/d

Similar to the above, it will remove any line with a number embedded in there...
  #6 (permalink)  
Old 01-06-2002
peter.herlihy peter.herlihy is offline
Registered User
  
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
Cool.... the answer I was looking for was how to use the wildcard ....which I can see is used by preceeding with a dot.

The rest is a peice of cake...and yeah - I did it with the numbers only - which became apparent as I worked through it. Thanks all.
  #7 (permalink)  
Old 01-07-2002
Kelam_Magnus's Avatar
Kelam_Magnus Kelam_Magnus is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
Lightbulb delete from the beginning of the line

Pete,

If you want to delete a specific recurring pattern at the beginning of the line you can use the "^". Or use the $ for patterns at the end of the line.

:g /^S[0-9]/d

This will work for deleting lines that begin that way.

Closed Thread

Bookmarks

Tags
regex, regular expressions

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 08:21 PM.


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