1834134 Members
1995 Online
110064 Solutions
New Discussion

vi editor help

 
SOLVED
Go to solution
Kenn Chen
Advisor

vi editor help

I want to add one work into each line in my file. E.g. i have a file called abc.txt and contents below lines.

KKCHUA 19981212 SINGAPORE
YYZZZZ 2001SDFG HONGKONG
YYZZZZ 2001SDFG TAIWAN

Add new word (NULL) at end of each line become :-

KKCHUA 19981212 SINGAPORE NULL
YYZZZZ 2001SDFG HONGKONG NULL
YYZZZZ 2001SDFG TAIWAN NULL
Cyber Zen
4 REPLIES 4
Steven Sim Kok Leong
Honored Contributor
Solution

Re: vi editor help

Hi,

:1,$s/$/ NULL$/g

Hope this helps. Regards.

Steven Sim Kok Leong
Wodisch
Honored Contributor

Re: vi editor help

Hello Idris,

to add something at the very end of the lines it is easiest to use the "substitue" command:

:1,$s/^V^M/NULL/

Attention: "^V" is Ctrl-V, and "^M" is the Return-key (or Ctrl-M, that's just the same)

HTH,
Wodisch
Steven Sim Kok Leong
Honored Contributor

Re: vi editor help

Hi,

Sorry, made a typo. Should be:

:1,$s/$/ NULL/g

Hope this helps. Regards.

Steven Sim Kok Leong
Michael Tully
Honored Contributor

Re: vi editor help

# vi yourfile

from the command prompt
:1,$s/$/ NULL/g

Save file
Anyone for a Mutiny ?