The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Parse Logfile output variable Ikon Shell Programming and Scripting 11 12-12-2008 10:37 AM
To parse through the file and print output using awk or sed script cdfd123 Shell Programming and Scripting 4 03-03-2008 12:07 PM
How to parse through a file and based on condition form another output file sivasu.india UNIX for Advanced & Expert Users 6 02-28-2008 04:59 AM
parse through one text file and output many sophiadun UNIX for Dummies Questions & Answers 14 02-20-2008 06:08 AM
Parse ping output palm101 Shell Programming and Scripting 3 11-11-2007 12:16 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-28-2009
FreddyG FreddyG is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 7
parse csv file, sha1 hash and output

I have a file, not really a csv, but containing delineated data just the same. Lets call that file "raw_data.txt". It contains data in the format of company name:fein number like this:

Code:
first company name:123456789
second company name:987654321
what i need to do is read this file, apply sha1 to the fein field and then output that into a new file, we'll call "hashed_data.txt". So hashed_data.txt should contain data like

Code:
first company name:f7c3bc1d808e04732adf679965ccc34ca7ae3441
second company name:bfe54caa6d483cc3887dce9d1b8eb91408f1ea7a
i have tried looping thru the file with awk like so

Code:
read FILE
while read line
do
        awk 'BEGIN{FS=OFS=":"}{print $1, $2}'
done < $FILE
but I'm stuck on how to run the second field thru sha1sum
  #2 (permalink)  
Old 01-28-2009
danmero danmero is online now Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,419
bash solution.
Code:
IFS=":" && \
while read name fein
        do echo "$name:"$(sha1 -qs $fein)
done < file > newfile
Note: You should read the sha1sum man

Last edited by danmero; 01-28-2009 at 11:30 AM.. Reason: Add note
  #3 (permalink)  
Old 01-28-2009
FreddyG FreddyG is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 7
thanks! checking it out now
  #4 (permalink)  
Old 01-28-2009
rwuerth rwuerth is offline
Registered User
  
 

Join Date: Jan 2009
Location: Va. Beach
Posts: 64
if your echo supports '-n' have you tried to put that into your echo statement?

Code:
echo -n "$name:"$(sha1sum <<< $fein)
I'm not sure if it will or wont work, I just don't know if it's been tried.
  #5 (permalink)  
Old 01-28-2009
FreddyG FreddyG is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 7
i think the command I'm actually going for is sha1sum. When i modified the first snipit you posted to this it seemed to work

Code:
IFS=":" && \
while read name fein
        do echo "$name:"$(sha1sum <<< $fein)
done < raw_data.txt > hashed_data.txt
however, it's getting a newline feed in the hash as well

the accurate hash of
123456789
should be
f7c3bc1d808e04732adf679965ccc34ca7ae3441

Code:
echo -n 123456789 | sha1sum
will produce this hash

so need a way to trim the newline feed out of there.

Code:
tr -d '\n'
but where would it go ion the above snipit?
  #6 (permalink)  
Old 01-28-2009
FreddyG FreddyG is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 7
Quote:
Originally Posted by rwuerth View Post
if your echo supports '-n' have you tried to put that into your echo statement?

Code:
echo -n "$name:"$(sha1sum <<< $fein)
I'm not sure if it will or wont work, I just don't know if it's been tried.
seems to just remove the new line feed between the lines, IE ouput is now

Code:
first company name:179c94cf45c6e383baf52621687305204cef16f9  -second company name:a1b42d633e975efc2f665bda21f94e419c1b6074  -
  #7 (permalink)  
Old 01-28-2009
rwuerth rwuerth is offline
Registered User
  
 

Join Date: Jan 2009
Location: Va. Beach
Posts: 64
Okay take the -n out of the echo.

try this before the echo statement

Code:
fein=`echo $fein | tr -d /\n/`
Or as I think about it, just

Code:
fein=`echo -n $fein`
Sponsored Links
Closed Thread

Bookmarks

Tags
awk, awk trim, bash, csv, md5sum, sha1sum, trim, trim awk

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0