vi delete question - SCO

This is a discussion on vi delete question - SCO ; Hello SCO gang, While editing a large file in 'vi' I'd like to remove all space from a given character to its left. Example: Jeff Hyman Bill Johnson Carol Channong ^--------------------* carolc@megas.net * By placing the cursor on the letter ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: vi delete question

  1. vi delete question


    Hello SCO gang,

    While editing a large file in 'vi' I'd like to remove
    all space from a given character to its left. Example:

    Jeff Hyman Bill Johnson Carol Channong ^--------------------*
    carolc@megas.net

    * By placing the cursor on the letter "c" above and pressing "d0"
    will remove all the data to the left of the letter "c", and move
    the data to the right of the letter "c" to the far left.
    QUESTION: Is there a way I can do this with one quick sweep
    of a list of thousands of email addresses?

    TIA,
    Uncle Jeff
    .--.
    ___________________________ .-. | | _____________________________________
    Lone Star Software Corp. | | | | .-. Home of World Famous LONE-TAR(tm)
    Cactus International, Inc. | |_| | | | Backup Software for UNIX and LINUX
    Sales: 800.525.8649 _ |___ |_| | 24x7 Support Available
    Support: 301.829.1622 _| ~- | ___| RESCUE-RANGER(tm) and AIR-BAG(tm)
    http://www.LONE-TAR.com \, _} | | Disaster Recovery Software
    -------------------------- \( -- | | --------------------------------------
    | |


  2. Re: vi delete question

    Jeff Hyman typed (on Fri, Oct 26, 2007 at 02:42:57PM -0400):
    |
    | Hello SCO gang,
    |
    | While editing a large file in 'vi' I'd like to remove
    | all space from a given character to its left. Example:
    |
    | Jeff Hyman | Bill Johnson | Carol Channong | ^--------------------*
    | carolc@megas.net
    |
    | * By placing the cursor on the letter "c" above and pressing "d0"
    | will remove all the data to the left of the letter "c", and move
    | the data to the right of the letter "c" to the far left.
    | QUESTION: Is there a way I can do this with one quick sweep
    | of a list of thousands of email addresses?

    If I rephrase your wish this way

    Delete from the beginning of each line through the first
    '<' on that line.

    then I think you want

    sed 's!^.* new_list


    How come your list doesn't come with a final '>' on each line?

    If it does, and looks more like this:

    Jeff Hyman
    Bill Johnson
    Carol Channong

    Then this will give you just the characters between the angle brackets:

    sed 's!^.*<\(.*\)>.*$!\1!' old_list > new_list

    --
    JP

  3. Re: vi delete question

    In article <20071026184257.GA22424@lonestar.cactus.com>,
    Jeff Hyman wrote:
    >
    >Hello SCO gang,
    >
    > While editing a large file in 'vi' I'd like to remove
    >all space from a given character to its left. Example:
    >
    >Jeff Hyman >Bill Johnson >Carol Channong > ^--------------------*
    >carolc@megas.net
    >
    >* By placing the cursor on the letter "c" above and pressing "d0"
    > will remove all the data to the left of the letter "c", and move
    > the data to the right of the letter "c" to the far left.
    > QUESTION: Is there a way I can do this with one quick sweep
    > of a list of thousands of email addresses?


    If all of your data look like that, then:
    :%s/.*
    John
    --
    John DuBois spcecdt@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/

  4. Re: vi delete question

    On Fri, Oct 26, 2007, Jeff Hyman wrote:
    >
    >Hello SCO gang,
    >
    > While editing a large file in 'vi' I'd like to remove
    >all space from a given character to its left. Example:
    >
    >Jeff Hyman >Bill Johnson >Carol Channong > ^--------------------*
    >carolc@megas.net
    >
    >* By placing the cursor on the letter "c" above and pressing "d0"
    > will remove all the data to the left of the letter "c", and move
    > the data to the right of the letter "c" to the far left.
    > QUESTION: Is there a way I can do this with one quick sweep
    > of a list of thousands of email addresses?


    If all of them have a ``<'' character before the address one
    could do this with ``:%s/.*''

    If the lines are of the more common form for e-mail addresses:
    Bill Campbell
    John Doe

    Then this should do the trick ``:%s/.*<\(.*\)>.*/\1/''
    which will capture everything between the ``<'' and ``>''
    replacing the entire line with the e-mail address.

    Bill
    --
    INTERNET: bill@celestial.com Bill Campbell; Celestial Software LLC
    URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way
    FAX: (206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676

    It will be of little avail to the people that the laws are made by men of
    their own choice if the laws be so voluminous that they cannot be read, or
    so incoherent that they cannot be understood.
    -James Madison, Federalist Paper #62

  5. Re: vi delete question

    On Fri, 26 Oct 2007 14:42:57 -0400, Jeff Hyman
    wrote:

    >
    >Hello SCO gang,
    >
    > While editing a large file in 'vi' I'd like to remove
    >all space from a given character to its left. Example:
    >
    >Jeff Hyman >Bill Johnson >Carol Channong > ^--------------------*
    >carolc@megas.net
    >
    >* By placing the cursor on the letter "c" above and pressing "d0"
    > will remove all the data to the left of the letter "c", and move
    > the data to the right of the letter "c" to the far left.
    > QUESTION: Is there a way I can do this with one quick sweep
    > of a list of thousands of email addresses?
    >
    >TIA,
    >Uncle Jeff


    Yet another option (assuming, as others have mentioned, that you truly
    don't have ">" at the end of each address):

    cut -d"<" -f2 org_file > new_file



    Scott McMillan

  6. Re: vi delete question

    Scott McMillan typed (on Mon, Oct 29, 2007 at 09:17:44AM -0400):
    | On Fri, 26 Oct 2007 14:42:57 -0400, Jeff Hyman
    | wrote:
    |
    | >Hello SCO gang,
    | >
    | > While editing a large file in 'vi' I'd like to remove
    | >all space from a given character to its left. Example:
    | >
    | >Jeff Hyman | >Bill Johnson | >Carol Channong | > ^--------------------*
    | >carolc@megas.net
    | >
    | >* By placing the cursor on the letter "c" above and pressing "d0"
    | > will remove all the data to the left of the letter "c", and move
    | > the data to the right of the letter "c" to the far left.
    | > QUESTION: Is there a way I can do this with one quick sweep
    | > of a list of thousands of email addresses?
    | >
    | >TIA,
    | >Uncle Jeff
    |
    | Yet another option (assuming, as others have mentioned, that you truly
    | don't have ">" at the end of each address):
    |
    | cut -d"<" -f2 org_file > new_file
    |
    | Scott McMillan

    For starters... thanks for all the helpful replys.

    1. JP was correct in needing to remove everything
    to the right of the ">" as well as everything to
    the left of the first "<".
    The most common (and ideal) string for editing would be:
    From: "Jeff Hyman"
    ^^^^^^^^^^^^^^^--- and only end up with this.
    Here (again) is JPs code that does this:
    sed 's!^.*<\(.*\)>.*$!\1!' old_file > new_file

    2. Here are some examples of some remaing lines that do NOT get removed:
    # grep "mailto:" old_file
    From: Bill Johnson [mailto:bill_johnson@yahoo.com]
    ^^^^^^^^^^^^^^^^^^^^^^
    From: Bill Johnson [mailto:bill_johnson@yahoo.com]=20
    ^^^ The equal-sign20
    pops up often also.

    a.. It would be a more complete cleaning if I could also isolate
    the email address in #2 above so the result is only:
    bill_johnson@yahoo.com
    b.. strip out any string "=20"

    JP's input saved over 90% of the labor. Getting to 100% is wishful
    thinking, but always a plus :-)

    Best Regards,
    Jeff H


  7. Re: vi delete question

    Jeff Hyman typed (on Mon, Oct 29, 2007 at 01:26:48PM -0400):
    | Scott McMillan typed (on Mon, Oct 29, 2007 at 09:17:44AM -0400):
    | | On Fri, 26 Oct 2007 14:42:57 -0400, Jeff Hyman
    | | wrote:
    | |
    | | >Hello SCO gang,
    | | >
    | | > While editing a large file in 'vi' I'd like to remove
    | | >all space from a given character to its left. Example:
    | | >
    | | >Jeff Hyman | | >Bill Johnson | | >Carol Channong | | > ^--------------------*
    | | >carolc@megas.net
    | | >
    | | >* By placing the cursor on the letter "c" above and pressing "d0"
    | | > will remove all the data to the left of the letter "c", and move
    | | > the data to the right of the letter "c" to the far left.
    | | > QUESTION: Is there a way I can do this with one quick sweep
    | | > of a list of thousands of email addresses?
    | | >
    |
    | For starters... thanks for all the helpful replys.
    |
    | 1. JP was correct in needing to remove everything
    | to the right of the ">" as well as everything to
    | the left of the first "<".
    | The most common (and ideal) string for editing would be:
    | From: "Jeff Hyman"
    | ^^^^^^^^^^^^^^^--- and only end up with this.
    | Here (again) is JPs code that does this:
    | sed 's!^.*<\(.*\)>.*$!\1!' old_file > new_file
    |
    | 2. Here are some examples of some remaing lines that do NOT get removed:
    | # grep "mailto:" old_file
    | From: Bill Johnson [mailto:bill_johnson@yahoo.com]
    | ^^^^^^^^^^^^^^^^^^^^^^
    | From: Bill Johnson [mailto:bill_johnson@yahoo.com]=20
    | ^^^ The equal-sign20
    | pops up often also.
    |
    | a.. It would be a more complete cleaning if I could also isolate
    | the email address in #2 above so the result is only:
    | bill_johnson@yahoo.com
    | b.. strip out any string "=20"
    |
    | JP's input saved over 90% of the labor. Getting to 100% is wishful
    | thinking, but always a plus :-)

    Hey, no problem, You wish, therefore I think :-)

    OK, cook up a second subsititution command to deal with it.

    You might want to commit this to a file, maybe "getBareEmail":

    #!/bin/ksh
    #@(#) return just the mail address itself.

    USAGE="Usage: $0 input_file output_file"

    [[ $# -ne 2 ]] && echo $USAGE && exit

    sed '
    s!^.*<\(.*\)>.*$!\1!
    s=^.*:\(.*\)].*$=\1=
    ' <$1 >$2

    --
    JP

+ Reply to Thread