Re: Please help

2006-05-24 Thread Ricky Zhou

On 5/24/06, Tien Pham [EMAIL PROTECTED] wrote:

Dear all

I have a very large file containing 7000 lines of data in a single column.
Below is a sample. Many of them are 7 digit numbers and others are 8 digit
numbers. For those 7 digit numbers, I need to add number 0 at the beginning
of it. Can someone please show me a command to do it all in one hit? Those
7 digits numbers have no regular patterns, except that they have 7 digits,
and the order of all numbers in the column has to remain unchanged.

Can't you simply replace seven digits surrounded by new lines?
Something like this:
:%s/^\(\d\{7\}\n\)/0\1/

Hope this helps,
Ricky


Re: Please help

2006-05-24 Thread Gary Johnson
On 2006-05-25, Tien Pham [EMAIL PROTECTED] wrote:
 Dear all
 
 I have a very large file containing 7000 lines of data in a single column. 
 Below is a sample. Many of them are 7 digit numbers and others are 8 digit 
 numbers. For those 7 digit numbers, I need to add number 0 at the beginning 
 of it. Can someone please show me a command to do it all in one hit? Those 
 7 digits numbers have no regular patterns, except that they have 7 digits, 
 and the order of all numbers in the column has to remain unchanged.

g/^\d\{7}$/s/^/0/

HTH,
Gary

-- 
Gary Johnson | Agilent Technologies
[EMAIL PROTECTED] | Wireless Division
 | Spokane, Washington, USA


Re: Please help

2006-05-24 Thread Steve Hall
On Thu, 2006-05-25 at 10:55 +1000, Tien Pham wrote:
 
 I have a very large file containing 7000 lines of data in a single
 column. Below is a sample. Many of them are 7 digit numbers and
 others are 8 digit numbers. For those 7 digit numbers, I need to add
 number 0 at the beginning of it. Can someone please show me a
 command to do it all in one hit? Those 7 digits numbers have no
 regular patterns, except that they have 7 digits, and the order of
 all numbers in the column has to remain unchanged.

  %s/^\(\d\d\d\d\d\d\d\)$/0\1/ge

See

  :help :substitute
  :help pattern-overview


-- 
Steve Hall  [ digitect mindspring com ]
:: Cream... something good to put in your Vim!
::   http://cream.sourceforge.net



Re: Please help

2006-05-24 Thread Tien Pham

Hi Ricky, Pete, Gary and Alan

Wonderful, thanks all of you very much for your kind and prompt help. It 
works very well Pete.


Regards
tien




At 11:07 AM 25/05/2006 +1000, Pete Johns wrote:

On Thu, 2006-05-25 at 10:55:51 +1000, Tien Pham sent:
Dear all

Hi Tien

I have a very large file containing 7000 lines of data in a
single column.  Below is a sample. Many of them are 7 digit
numbers and others are 8 digit numbers. For those 7 digit
numbers, I need to add number 0 at the beginning of it. Can
someone please show me a command to do it all in one hit? Those
7 digits numbers have no regular patterns, except that they have
7 digits, and the order of all numbers in the column has to
remain unchanged.

:%s/^\d\{7}$/0/

On every line that has exactly seven digits replace the match
with a zero followed by the entire match.

See :help :s

Your help is greatly appreciated.

You're very welcome;

--paj

--
Pete Johns   http://johnsy.com/
Tel/Fax numbers and IM information   http://johnsy.com/contact/
Road Tripping Storyhttp://johnsy.com/20060522123211