1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: looking help on VI search and replace

Discussion in 'Linux and Unix' started by jlaanep, Oct 15, 2008.

Thread Status:
Not open for further replies.
Advertisement
  1. jlaanep

    jlaanep Thread Starter

    Joined:
    Oct 15, 2008
    Messages:
    4
    Hello,

    I'm attempting to manipulate a large data file. What I'm attempting to do is find a bracket '(' then on the same line find a character followed by a ',' ([A-Za-z],) then on the same line find a space then delete the space and everything after it on that line.

    So far what I've been able to come up with results in an error (E488: Triailing Characters). I'm not sure what I'm doing wrong as my vi and reg expressions are basic at best. If someone could manipulate what I have or offer some suggestions that would be great.

    Here's what I've come up with (both result in the same error):

    s/(/;/[A-Za-z],/;/\ //

    s/\(/;/[A-Za-z]\,/;/\ //


    TIA
     
  2. lotuseclat79

    lotuseclat79

    Joined:
    Sep 12, 2003
    Messages:
    20,583
    Hi jlaanep,

    I would not use vi for this problem, but nawk which is a variant of awk since it contains substring functions that can simplify what you are trying to do - i.e. each line you are interested in must contain a '(', followed by some characters and a ',' followed by zero or more characters and a space - at which time you delete from the position of the space to the end of the line.

    Try to search for an awk, gawk or nawk tutorial on the Internet, and learn how to invoke an awk program in a file, as your processing requirements are more than just simple enough to use vi and regular expressions.

    -- Tom

    P.S. Reference: The AWK Programming Language by Aho, Kernighan, and Weinberger, Addison-Wesley Series in Computer Science
     
  3. TerryNet

    TerryNet Moderator

    Joined:
    Mar 23, 2005
    Messages:
    78,185
    First Name:
    Terry
    :g/\(([A-Za-z],[^ ]*\) .*/s//\1

    colon g slash backslash leftparen leftparen leftbracket A-Za-z rightbracket comma leftbracket ^ space rightbracket asterisk backslash rightparen space period asterisk slash s slash slash backslash 1
     
  4. jlaanep

    jlaanep Thread Starter

    Joined:
    Oct 15, 2008
    Messages:
    4
    Thanks to the both of you! I'll look up both of these tomorrow (or I guess today now) when I get into work!

    I'll let you know how it goes and the solution I found.

    jlaanep.
     
  5. TerryNet

    TerryNet Moderator

    Joined:
    Mar 23, 2005
    Messages:
    78,185
    First Name:
    Terry
    I must admit to disappointment that we haven't heard back from you. :( If I misunderstood your requirements I would be happy to try to make changes.
     
  6. jlaanep

    jlaanep Thread Starter

    Joined:
    Oct 15, 2008
    Messages:
    4
    Hello again guys!

    Sorry about not responding fast but I had a server down and haven't had a chance to look at the search/replace until this morning.

    Terry, your search/replace string did the trick, thanks again!

    JL.
     
  7. TerryNet

    TerryNet Moderator

    Joined:
    Mar 23, 2005
    Messages:
    78,185
    First Name:
    Terry
    You're welcome. Glad it worked for you. You can mark this "Solved" using the button at the upper left of your first post.
     
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/759443

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice