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:


(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.

  • 1
    Do the usernames : in them? – muru Apr 6 '18 at 3:58
  • no the colon is just an arbitrary seperator – Evan Foulk Apr 6 '18 at 4:28

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.txt

Should do it.

  • cat files*.txt - prints all lines to STDOUT
  • sed -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.


  • If you have ':' characters in only the passwords, this will still work.
  • 2
    You don't need the cat. sed ... files*.txt > ... would work fine. – muru Apr 6 '18 at 4:24
  • Thanks muru, I understand that. I'm not going for an optimum solution, rather one that helps explain what steps in the pipeline do. – dpb Apr 6 '18 at 4:28
  • 1
    (of which one step is entirely unnecessary). – muru Apr 6 '18 at 4:29
  • if it replaces everything up to the colon will it change the original files? – Evan Foulk Apr 6 '18 at 4:30
  • @EvanFoulk it will not. It's just changing the lines that were printed and passed into the pipeline. The original files stay in tact. – dpb Apr 6 '18 at 4:33

You can use cut:

cut -d: -f2- file1 file2 > output
  • -d: tells cut that the fields are separated with :, and
  • -f2- tells cut to output all fields from the second onwards.
  • due to errors in the original file this gave me a much cleaner output if i put -d;: will that also do the same for semicolon seperated password or should i put -d; -d: – Evan Foulk Apr 6 '18 at 4:47
  • @EvanFoulk cut only supports a single separator character. You'd be better off with sed if multiple characters can be separators. – muru Apr 6 '18 at 4:53
  • @EvanFoulk there are countless ways to do things like this, the tools here are just a couple of ways. Keep in mind you can also re-process the 'all-passwords.txt' using these same tools. Also, if you put ';' in the command line, make sure you surround it with single quotes. It has special meaning unless it's quoted like that. – dpb Apr 6 '18 at 4:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.