how to implement text, shell

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • quartz
    New Member
    • Aug 2007
    • 19

    how to implement text, shell

    I need to implement some text, date, into another text file. For instance, first line in 7 line and second line in 10 line of another text file?
    Thanks in advance.
  • arne
    Recognized Expert Contributor
    • Oct 2006
    • 315

    #2
    Originally posted by quartz
    I need to implement some text, date, into another text file. For instance, first line in 7 line and second line in 10 line of another text file?
    Thanks in advance.
    You could use sed for this, see also 'man sed'.

    For your example you could prepare a command file (stored in file 'comm'):

    Code:
    7 i lineSeven
    10 i lineTen
    The first column is the line number, the second the command ('i' for insert) and the third the new line.

    If you then invoke sed on your file to be changed (name: myFile):

    Code:
    sed -fcomm <myFile
    The output will have new lines 7 and 10.

    You may want to redirect things to a new file:

    Code:
    sed -fcomm >myNewFile <myFile
    HTH,
    arne

    Comment

    • ghostdog74
      Recognized Expert Contributor
      • Apr 2006
      • 511

      #3
      Originally posted by quartz
      I need to implement some text, date, into another text file. For instance, first line in 7 line and second line in 10 line of another text file?
      Thanks in advance.
      its better to show an input file, an output format that is desired and also any code that you have written so far.

      Comment

      • quartz
        New Member
        • Aug 2007
        • 19

        #4
        I will try your advice, bur in meantime I founded this command

        sed -e '1h;7G;1d' text > text1

        it is doing what I need.

        I have one more question.

        for new date I am using
        #!bin/bash
        date=`date+"%Y% m%d"`
        echo date$ > textfile
        .....

        I wont to have new date in text file in column e.g. 12?

        Thanks in advance

        Comment

        Working...