Find the answer to your Linux question:
Results 1 to 2 of 2
Hello All, I am new to this forum. I am currently facing a problem in manipulating files. I have two files called old-matter and new-matter # cat old-matter abc: this, ...
  1. #1
    Just Joined!
    Join Date
    Jan 2009
    Posts
    1

    Substitute specific lines with lines from another file

    Hello All,

    I am new to this forum. I am currently facing a problem in manipulating files.

    I have two files called old-matter and new-matter

    # cat old-matter

    abc: this, is a, sample, entry
    byi: white board, is white in color
    rtz: black, board is black
    qty: i tried, a lot
    asd: no solutions, found for this task

    abc: this is, the second, sample entry
    byi: second, entry of white board
    rtz: second, entry of black board
    qty: second, entry of trying
    asd: second, entry of no solutions

    abc: this is, the third, sample entry
    byi: third, entry of white board
    rtz: third, entry of black board
    qty: third, entry of trying
    asd: third, entry of no solutions

    ......
    ......
    ... and so on up to 1517 entries


    in this file, from the line begining with asd: to line ends with asd: is considered as one entry (or a paragraph).

    now i had created another file called new-matter, which is having ONLY the first line of the above said each entries(paragraph) in the newly formatted style, as the following;

    abc: newly updated, this, is a, sample, entry
    abc: newly updated, this is, the second, sample entry
    abc: newly updated, this is, the third, sample entry, with more info
    ....
    ....
    1517 lines



    Now i need to replace all the lines in the old-matter, which starts with abc: with the newly formatted abc: lines from the new-matter file. Here the critical thing, is, it should be replaced correctly (first paragraphs abc: should replace with first abc: in the new-matter and so on...), bcoz all the new entries are Uniq (this is actually an address list).


    Also i need to put a blank line above all the line starts with abc:



    Thanks in Advance...
    Edit/Delete Message

  2. #2
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    452
    welcome to the forum

    the hard part is reading from two files, but this
    might work: call the files A and B

    1. make frm each A paragraph one line (substitute
    "space" for <nl>)

    2. cut off first item "abc:..."

    3. paste B A (gets new "abc:..." on)

    4. "double-space," i.e. add blank lines

    5. restore <nl>s

    perhaps "sed" or "tr" for 1, "cut" for 2, "paste" for 3,
    "awk" for 4 & 5. Details an exercise for the reader.
    the sun is new every day (heraclitus)

Posting Permissions

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