I've got a couple of textfiles containing mails,usernames, passwords and emails in various formats.

Could someone help me to filter out the content I don't need?

For example, this Is one line of textfile1: ('RandomUserName','usernamehashhashhashahashshsas',0.000000000,0),

How can I filter away everything but the hash???

Number two: randomuser:hashashashashashashashashash:usermail@mail.com:\

Again, how can i filter out/remove everything but the hash, and remove the "\" at the end of each hash?

closed as unclear what you're asking by Kusalananda, thrig, GAD3R, mdpc, Michael Homer Feb 7 '17 at 3:21

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Exactly what would the expected output be from the input? – thrig Feb 6 '17 at 16:27
  • @thrig I don't see the issue. The OP did say what they wanted. – roaima Feb 7 '17 at 8:03
  • @roaima not really, is that first username part of the hash, or not? Is for "hashash" the whole thing matched, or exactly only hash? Same deal for the trailing "shsas" string, is that to be excluded, or is it something different? If they can't clarify their requirements... – thrig Feb 7 '17 at 16:31

There are a number of ways of handling this. The easiest is probably cut, which will do most of what you want straight off.


You can process this with a two command pipeline, which says to pick out the second comma-separated field from each line, and then delete single quotes from the result:

cut -d, -f2 datafile | tr -d "'"

The second part is easier as there are no quotes to remove.


A single command will be sufficient here:

cut -d: -f2 datafile
  • thank you!! Works, kinda.. the problem is that my file has ~5k rows which are identical to the ones i posted `('RandomUserName','...´ but terminal just filters and outputs the first two lines in my file, am i doing something wrong? – diddlydope Feb 6 '17 at 16:06
  • @diddlydope you are probably using a file with Windows line endings. Try running sed 's/\r//g' file > newfile and then using newfile instead. – terdon Feb 6 '17 at 16:12
  • I tried, but got the same results.. Just the two first lines shows as output – diddlydope Feb 6 '17 at 16:17
  • @diddlydope what type of system created these files? For both files please post the output of wc -l <datafile, where datafile is the file name. – roaima Feb 7 '17 at 8:14

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