[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: vi or vim -- ed, sed, awk, etc...



On Sun, 2005-07-17 at 18:05 -0500, bentley rhodes wrote:
> I want to write at a command prompt [such and such], and never have to 
> open or save a text file. simply by saying the program name and a 
> command, and the text i want in the file, *presto* it is in the text 
> file saved somewhere that i specified. that way if i wanted to format my 
> computer and have the install script i made insert lines of text into an 
> existing or non-existing file somewhere, i can do so without ever having 
> to open the thing as root and do the editing. i can simply use one 
> script to do a lot of things for me, like putting text into an existing 
> text file.

You do _not_ use the VI[sual] (vi) editor for that.
It's really designed to be interactive.

You either use its daddy, the ED[itor] (ed).
Or the S[tream] ED[itor] (sed).

"ed" is a line editor, designed to be either command line drive or
interactive.  "sed" adds a lot of additional capabilities.

There are also commands like "awk" that are designed to work on lines
that are independent fields (separated by whitespace or other
characters).  E.g., "awk" is commonly used to extract, parse or even
edit the /etc/passwd file (which is 7 fields separated by ":").

There is even the classic O'Reilly book, "Sed and Awk":  
  http://www.oreilly.com/catalog/sed2/index.html  

And if you really get sick of all the little commands available in UNIX
to edit text files (there are an _endless_ number ;-), you can always
just learn Perl (Practical Extraction and Report Language).  One of the
reasons Larry Wall invented it was because he thought there could be one
program that would replace all those little UNIX programs.  ;->

-- Bryan

P.S.  Now if you just need to append lines to a file, you can do that
directly in a shell:  
  echo "mytext" >> myfile
Or to add an entire file to the end of another:  
  cat addfile >> myfile

-- 
Bryan J. Smith                                     b.j.smith@ieee.org 
--------------------------------------------------------------------- 
It is mathematically impossible for someone who makes more than you
to be anything but richer than you.  Any tax rate that penalizes them
will also penalize you similarly (to those below you, and then below
them).  Linear algebra, let alone differential calculus or even ele-
mentary concepts of limits, is mutually exclusive with US journalism.
So forget even attempting to explain how tax cuts work.  ;->



-
To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.