Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2004
    Posts
    46

    Unanswered: insert into a file

    Hi,

    I want to insert couple of lines into a file globally,

    for example in a file file.txt

    aaa
    bbb
    ccc
    ddd
    mark
    firstline
    secondline
    eee
    fff

    how do i insert 2 lines 'firstline' and 'secondline' into files after 'mark'.

    Thanks
    ~mark

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool


    Try this:
    Code:
    #!/bin/ksh
    for file in *.txt
    do
      n=$(grep -n '^mark' ${file}|cut -d: -f1)
      (( n += 1 ))
      ex $1 <<!
    $n
    i
    firstline
    secondline
    .
    :w
    !
    done

    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  3. #3
    Join Date
    Jun 2004
    Posts
    46
    Thanks for solution


    ~Mark.

  4. #4
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool


    You are wellcome!
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •