Tyler Tyler - 1 year ago 66
Bash Question

Separate huge Hash file into one file based on content (shell scripting)

I have a huge file of hashes that is displayed like this:

username:values:values:password hash:::

username:values:values:password hash:::

username:values:values:password hash:::

and so on....

I need to take the hashes with this format for username and put them into another file.

the username needs to start with a letter followed by 6 digits.

Examples of usernames i want to put into a new file:

However there are a ton of other usernames in this hash file that I do not want that may look like this:

etc etc

Preferably in bash or C++.

I was told I should use grep or sed

I'm on a ubuntu linux machine.

Answer Source

You can use below sed command:

sed -n '/^[a-zA-Z]\{1\}[0-9]\{6\}:/p' hash_file > output_file

This sed command looks for lines starting with 1 alphabet ( [a-zA-Z]\{1\} ) followed by 6 numbers ( [0-9]\{6\}) followed by :.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download