LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-25-2014, 12:08 PM   #1
cazanadrian
LQ Newbie
 
Registered: Oct 2012
Posts: 6

Rep: Reputation: Disabled
Question awk and md5sum


Hello there,

I need to calculate and append to a csv file the md5sum after certain fields.

I tried to find something easy to understand but I got stuck.

The below command replaces field $2 with it's hash

Code:
# echo "a|b|c|d|e|f|g|h|i|j" | awk -F '|' 'BEGIN { OFS = "|" }{command="echo "$2"|md5sum" ;command | getline $2; close(command);sub(/[[:blank:]].*/,"",$2); print $0}'
# a|3b5d5c3712955042212316173ccf37be|c|d|e|f|g|h|i|j
What I need, is to calculate the md5sum after the fields $2 $5 $9 and append to the file as first column.

Output example:

Code:
<md5sum(bei)>|a|b|c|d|e|f|g|h|i|j
Any help?

Thank you
 
Old 06-25-2014, 07:26 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I am not sure I see where you are stuck? Use the alternate version of getline to place the md5sum in a variable and the print the variable followed by the line value.

If I have misunderstood, please explain a little further?
 
  


Reply

Tags
awk, md5sum



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
turning awk command line entries into awk scripts tabbyagirl Linux - Newbie 5 08-22-2013 12:46 AM
[SOLVED]Wierd AWK behavior / AWK not reading first line. Involar Linux - Newbie 9 11-28-2012 10:53 AM
awk error awk: line 2: missing } near end of file boscop Linux - Networking 2 04-08-2012 10:49 AM
[SOLVED] call awk from bash script behaves differently to awk from CLI = missing newlines titanium_geek Programming 4 05-26-2011 09:06 PM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 04:11 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration