ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    How can I duplicate a line on a file?

    IT Discussion
    2
    5
    159
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • IRJI
      IRJ
      last edited by

      I am running a command to generate a random password to a file. It creates a one line file, but I need the file to be two lines and have the same password on both lines (obviously)

      tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1 > /tmp/tmp1.txt

      Essentially file looks like this:

      cat /tmp/tmp1.txt 
      zPZ0ud81Q0gSjXKTDSLuP2Wz8PQIds
      
      

      I need it to look like this:

      cat /tmp/tmp1.txt 
      zPZ0ud81Q0gSjXKTDSLuP2Wz8PQIds
      zPZ0ud81Q0gSjXKTDSLuP2Wz8PQIds
      
      1 Reply Last reply Reply Quote 0
      • DustinB3403D
        DustinB3403
        last edited by

        Sed should be able to do this.

        From here

        sed -n $a,$b'p' infile

        IRJI 1 Reply Last reply Reply Quote 1
        • IRJI
          IRJ @DustinB3403
          last edited by IRJ

          @DustinB3403 said in How can I duplicate a line on a file?:

          Sed should be able to do this.

          From here

          sed -n $a,$b'p' infile

          How does a = 2 and b =4 ? I am not understanding that part.

          DustinB3403D 1 Reply Last reply Reply Quote 0
          • DustinB3403D
            DustinB3403 @IRJ
            last edited by

            @IRJ In that example a is line 2 and b is line 4.

            1 Reply Last reply Reply Quote 0
            • IRJI
              IRJ
              last edited by

              Here is a much simplier way to do this.

              head -1 /tmp/tmp1.txt >> /tmp/tmp1.txt

              1 Reply Last reply Reply Quote 2
              • 1 / 1
              • First post
                Last post