How can I duplicate a line on a file?
-
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
-
-
@DustinB3403 said in How can I duplicate a line on a file?:
Sed should be able to do this.
sed -n $a,$b'p' infile
How does a = 2 and b =4 ? I am not understanding that part.
-
@IRJ In that example a is line 2 and b is line 4.
-
Here is a much simplier way to do this.
head -1 /tmp/tmp1.txt >> /tmp/tmp1.txt