How to pull bulk text out of file and paste it into another file?

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.

2

2 Answers

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

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.

Notes:

  • If you have ':' characters in only the passwords, this will still work.
10

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like