Trying to create a CSV file from a text file in Ubuntu
I have a text file that contains passwords and their respective hashes that is formatted as such:
'plaintext password'
'SHA256 hash'
'SHA3-512 hash'
This format continues for several more passwords. Each password and hash has its own line within the file. Each of the hashes below the 'plaintext password' are its respective hashes. I want to create a CSV file that will end up looking like this:
'plaintext password','SHA256 hash','SHA3-512 hash'
Essentially, I want to combine those three fields into one line for each password, delimited by commas for each field. I have tried searching for similar situations to mine but with no avail. I have tried awk as well as tr -s, but I haven't been able to get exactly what I want. I would appreciate the help!
You can try
paste -d, - - - < file.txt > file.csv
The paste
command generally merges lines of files side-by-side (with an optional delimiter supplied by -d
). In this case we are telling it to read the standard input stream 3 times - - -
instead.