skip to main | skip to sidebar

Random

Friday, June 6, 2008

vi search and replace with regular expressions

in vi, to search and replace:

:%s/search_phrase/replace_phrase/

with regular expressions:

.* matches one or more characters

so to get rid of the first two columns, separated by spaces

ie

2395 4586 3496
146434 6 3945

:%s/.* .* //

so it becomes:

3496
3945

or you could also do
:%s/[0-9]* [0-9]* //
Posted by Kathy at 6:47 PM
Labels: command, regular expressions, replace, search, vi

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Blog Archive

  • ►  2012 (2)
    • ►  June (1)
    • ►  April (1)
  • ►  2010 (5)
    • ►  May (1)
    • ►  March (1)
    • ►  February (2)
    • ►  January (1)
  • ►  2009 (4)
    • ►  August (1)
    • ►  April (1)
    • ►  March (2)
  • ▼  2008 (20)
    • ►  November (2)
    • ►  September (4)
    • ▼  June (10)
      • tcpdump for capturing packets and headers
      • Shell script for loops
      • List only directories in Unix
      • Parenthesized search and replace in vi
      • vi search and replace with regular expressions
      • Reformatting drives in unix
      • Execute shell commands from java
      • What line number you're on in vi
      • vi commands - insert at beginning or end of every ...
      • Listing directory sizes in Unix
    • ►  May (4)

About Me

Kathy
View my complete profile