Ok so i have a few files which contains emails and passwords. I want to make a single file of only the passwords, of all the files, without altering the originals. Each line is structured as so:
:password(there is no space between either the email or the password from the colon)
I was trying to figure out how to grep the file and pipeline the text into a new file but im not so sure on how to write the command. Please help thankyou.
22 Answers
You can use cut:
cut -d: -f2- file1 file2 > output-d:tellscutthat the fields are separated with:, and-f2-tellscutto output all fields from the second onwards.
Assuming no colon characters in the email addresses, For a bunch of files, let's call them files*.txt:
cat files*.txt | sed -e 's/[^:]*://' > all-passwords.txtShould do it.
cat files*.txt- prints all lines to STDOUTsed -e 's/[^:]*://'- replace everything up to the first ':' on the line with "nothing"> all-passwords.txt- create/overwrite a file called all-passwords.txt>> all-passwords.txt- If you were to use>>, it will only create or append to the file, not overwrite it.
Notes:
- If you have ':' characters in only the passwords, this will still work.