Hashing URLs

So, I am writing a script that will read output from Bulk Extractor (which gathers data based on regular expressions). My script then reads the column that has the URL found, hashes it with MD5, then outputs the URL and hash to a file.

Where I am stuck on is that I want to read the bulk extractor output, line by line. I want to take the 2nd column, and add that as a variable named "url". I then want to take that URL, and hash it with MD5 and assign that to the variable "hash".

I then want to output $url and $hash to an output file, both on the same line.

But, when I use :

while read line
	do
		url=`awk '{print $2}'`
		hash=`awk '{print $2}' | md5sum`
		echo $url
	done < $iname/url.txt

to walk through the input file, line by line, it globs them all together. $url has EVERY URL, and $hash is a hash value of ALL the URLs.

I know this snippet of code works - I've used it before. So, what is going on?

Here is a snippet of the input :

1691	http://www.pof.com/inbox.aspx_	\007\0000\0001\0002\0003\000(\0004_\020\035http://www.pof.com/inbox.aspx_\0200Online Dating 
1874	http://www.pof.com/sendmessage.aspx	WasHTTPNonGet_\020#http://www.pof.com/sendmessage.aspx[401152043.2\020R\011_
1927	http://www.pof.com/inbox.aspx?messagesent=1&Guid=63929064&SID=dnia5geyks5fjvr2hfesqwbg#in	01152043.2\020R\011_\020Yhttp://www.pof.com/inbox.aspx?messagesent=1&Guid=63929064&SID=dnia5geyks5fjvr2hfesqwbg#in�\000F\020\014\020\021�\000H\000\025\000I\000\025
2101	http://www.pof.com/viewallmessages.aspx?sender_id=41561852&message_id=17458470377&Guid=63929064&SID=dnia5geyks5fjvr2hfesqwbg_	7\000C\000D\000E\000G\000J\000M_\020|http://www.pof.com/viewallmessages.aspx?sender_id=41561852&message_id=17458470377&Guid=63929064&SID=dnia5geyks5fjvr2hfesqwbg_\020.POF.com Free O

I doubt it:
iname is undefined.
$2 is undefined (or, at least, has nothing to do with your input file).
hash is NOT output to anywhere.
url and hash , in your snippet, won't assemble values after value.
An output file is not defined.
And the input file looks extremely garbled.

I guess, what you told the code to do...

Like I said, it is a snippet, even more so, it is a snippet of a work in progress. So, all the undefined things - are. And the outputs you say are missing, will be put in place later.

My question was the while structure and why it is globbing data instead of stepping through line by line. Not whether or not variables are defined.

And by "extremely garbled", you mean a tab separated value text document, then yes, it is "extremely garbled".

I don't care what kind of snippet this is, RudiC is correct. This snippet can't work (even if the variables are defined to reasonable values). You have two invocations of awk with no input specified. Presumably the 1st one will gobble up all of the data remaining in $iname/url.txt after the read in the while loop grabbed the 1st line. Then the 2nd awk will immediately hit end-of-file.

You came here asking for help.
You insulted the person who pointed out that the data you supplied was incomplete (thereby making analysis difficult).
This is a great way to discourage readers in this forum who might consider trying to help solve your problem from posting any other responses.

What is this ? do you know the rules of this forum

(1) No flames, shouting (all caps), sarcasm, bullying, profanity or arrogant posts.

Here people are spending there time to help others, and they are not getting salary for that, if you need help in future in this forum behave gently. You should get infraction for this. And I know RudiC, without meaning he never answer/reply. Really I personally felt very bad that you are insulting such a great Advisor who spends his time for others. Don't repeat this again.

Akshay Hegde

I did come here for help, he wasn't helpful, and was insulting.

I get what you're saying about 1 awk instance gobbling up all the incoming data. Thank you, that is helpful. I guess I am at a loss on how to proceed. I need to take the data from a line, and do two things with it. Any suggestions for how to proceed?

The input is supplied by < $iname/url.txt, is it not? I mean the while loop is looping through something?

i would use bash to split the file first

while IFS=$'\t' read -r id url _; do
    hash=$(printf '%s' "$url" | md5sum)
    echo "$hash $url"
done < "$iname"/url.txt

From this I gather you are not the least bit sorry for your behavior. Please rethink and understand that we do not tolerate this kind of attitude and with good reason.
This thread is closed..