Using Awk or Sed to tack on a statement at the end of a specific line

后端 未结 3 521
花落未央
花落未央 2020-12-02 01:01

I have a file I named poscar1.cif, and I would like to insert the contents of a variable at a specific line in this file.

For example, line 24

3条回答
  •  醉话见心
    2020-12-02 01:52

    You can use sed to do it, depending on your answer to dawg's question as

    sed -i -e '24s/$/5.3827/' poscar1.cif
    

    or if it's the pattern

    sed -i -e '/_cell_length_a/s/$/5.3827/' poscar1.cif
    

    The first goes to the line with the given number, the later will apply on any line that matches the pattern in the first set of slashes. In either case it will then "replace" the end of the line with the value between the final two slashes.

提交回复
热议问题