Re: add a character to a line...



On 2006-04-27, onlineviewer <lancerset@xxxxxxxxx> wrote:
Hello,

How do you add a word or a character to the beginning of a line in a
file? I want to add a comment '#' where the string 'var' appears in a
file, globally. Like:

#### before:
bla
Var
bla

#### after:
bla
#Var
bla

Thanks,,,


To change the file directly, you can use ed (or ex):

# On every line where var or Var occurs as a word (e.g., exclude
# "variety"), add '#' to the beginning of the line:
echo 'g/\<[vV]ar\>/s/^/#/
wq'|ed file

It's easy to put this in a for loop to process several files.

--

*** Posted via a free Usenet account from http://www.teranews.com ***
.



Relevant Pages

  • Re: FAQ Topic - How do I trim whitespace - LTRIM/RTRIM/TRIM?
    ... loop to be constant during that loop, ... function rTrim{var k = str.length-1 ... The character l should not be used where it might be, even momentarily, ... for symmetry trimR, matching trim in case. ...
    (comp.lang.javascript)
  • Re: add a character to a line...
    ... On 2006-04-27, onlineviewer wrote: ... How do you add a word or a character to the beginning of a line in a ... I want to add a comment '#' where the string 'var' appears in a ...
    (comp.unix.programmer)
  • Re: this/prototype problem?
    ... instantiating new instances of the classes.... ... The prototype applies to all SomeClass objects. ... var privateVariable = ''; ... bla bla bla... ...
    (comp.lang.javascript)
  • add a character to a line...
    ... How do you add a word or a character to the beginning of a line in a ... I want to add a comment '#' where the string 'var' appears in a ...
    (comp.unix.programmer)
  • Re: add a character to a line...
    ... onlineviewer wrote: ... How do you add a word or a character to the beginning of a line in a ... I want to add a comment '#' where the string 'var' appears in a ...
    (comp.unix.programmer)