md5sum output append


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting md5sum output append
# 1  
Old 06-18-2011
md5sum output append

Hi there,

I have 2 fairly simple lines I am running and both work as expected, but I am trying to append the two of them to output a single line.

The first command get the MAC times of each file :-
Code:
find /media/Vista/Garmin/PCBSMP2/ -type f -printf "%A+ (a) %p\n%T+ (m) %p\n%C+ (c) %p\n"

And the output is :
Code:
2009-10-25+16:01:05.8765787000 (a) /media/Vista/Garmin/PCBSMP2/eula_ENU.txt
2008-03-12+08:36:16.0000000000 (m) /media/Vista/Garmin/PCBSMP2/eula_ENU.txt
2009-10-25+16:01:05.8765787000 (c) /media/Vista/Garmin/PCBSMP2/eula_ENU.txt

The second command is simply calculates the md5sum of each file:-
Code:
find /media/Vista/Garmin/ -type f -print0 | xargs -0 md5sum

And the output is :-
Code:
12e6bdb52d0036cabd6f898def29dd6a  /media/Vista/Garmin/Training CenterSVE.dll
4b4f81c294b9a07479f4f4f8ff20e58c  /media/Vista/Garmin/gStart.exe
32da0f05975b3426c0ad76296abf3073  /media/Vista/Garmin/gStart_Lang.dll

So what I would like to do is have a single command that when run, not only outputs the MAC times but also appends the files md5sum.. like so
Code:
2009-10-25+16:01:05.8765787000 (a) /media/Vista/Garmin/PCBSMP2/eula_ENU.txt 12e6bdb52d0036cabd6f898def29dd6a
2008-03-12+08:36:16.0000000000 (m) /media/Vista/Garmin/PCBSMP2/eula_ENU.txt 12e6bdb52d0036cabd6f898def29dd6a
2009-10-25+16:01:05.8765787000 (c) /media/Vista/Garmin/PCBSMP2/eula_ENU.txt 12e6bdb52d0036cabd6f898def29dd6a

I realise that there will be duplication of the md5 hash 3 times for each file but thats cool.

Any help is appreciated.

Last edited by Franklin52; 06-18-2011 at 02:04 PM.. Reason: Please use code tags, thank you
# 2  
Old 06-18-2011
I am not sure if this would help you but you can try:

Code:
command1 > file1.txt

will write the output of command1 to file1.txt

Now,
Code:
command2 >> file1.txt

will append command2 output to the existing file1.txt
# 3  
Old 06-18-2011
Hi dahlia84,
Unfortunately that method wont work as the second command would append the data to the end of the file, what I really need is one line of output with the outputs of both commands written together on one line... but thanks a million for your reply.
# 4  
Old 06-18-2011
Oh sorry, I am not on a Unix machine now but can you please try this and tell me if it works?

Code:
(command1; command2 )> filename.txt

# 5  
Old 06-18-2011
Hi dahlia84,
No that does the same thing again, runs command one first writes to a file, and the runs command 2.
# 6  
Old 06-18-2011
My bad. I shall give this one last try. I do not want to waste you time though.

Code:
echo `(command1; command2 )` > filename.txt

Try using echo with -n option as well because that is the option which writes the output in one single line.

If this also does not work then I am sorry! Smilie
# 7  
Old 06-18-2011
not at all its cool.. I tried the last code but alas it dint pretty much the same again...
anyway not to worry, and thanks a million for giving it a shot or 3 Smilie...

all the best.

---------- Post updated at 03:10 PM ---------- Previous update was at 01:49 PM ----------

Hi, I managed to get this to work for me. Please close.

Here is how I got it to work.

Code:
find /media/Vista/Garmin/ -type f -printf "%A+ (a),%6s, %p\n%T+ (m),%6s, %p\n%C+ (c),%6s, %p\n" | while read line;   
do   
name="$(echo $line | cut -d, -f2)";   
hash="$(echo $name | md5sum | awk -F" " '{print $1}')";   
echo $line $hash;   
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

WHy do we need both append and output directives?

Hi, I was reviewing a shell script and I found this line: yum -y update >> >(/usr/bin/tee /var/log/file) I have tried removing the >> directive and all that will occur is that the file will be created--nothing gets put in the file. If I put back the >> directive it works. If I remove the... (3 Replies)
Discussion started by: mojoman
3 Replies

2. Shell Programming and Scripting

How to append the output in a new column?

input1 john 20 bob 30 input2 john 60 bob 100 cat input1 >> output cat input2 >> output ouput john 20 bob 30 john 60 bob 100 desired output input1 input1 input2 input2 john 20 john 60 (3 Replies)
Discussion started by: quincyjones
3 Replies

3. Shell Programming and Scripting

Append to a file repeating output

Hello, i'm trying to force a command to read every second from an interface watch -n1 (command) /dev/x | cat >> output but it continue to overwrite the file, without append the content Thanks and advace for help as usual regards (4 Replies)
Discussion started by: Board27
4 Replies

4. Shell Programming and Scripting

How to append a value to the output after using sed command?

Hi All, I have a file where I am converting newlines to comma separated values but I would like to append zero if the output is empty Here is the command I am using sed -n -e 'H;${x;s/\n/,/g;s/^,//;p;}' test1.txt test1.txt will have comma seperated values but sometimes this file can be... (6 Replies)
Discussion started by: rajeevm
6 Replies

5. Shell Programming and Scripting

append an output file with two columns

Hi All, can you help me with this: grep XXX dir/*.txt|wc -l > newfile.txt - this put the results in the newfile.txt, but I want to add another column in the newfile.txt, string 'YYYYY', separated somehow, which corresponds on the grep results? For example grep will grep XXX dir/*.txt|wc -l >... (5 Replies)
Discussion started by: apenkov
5 Replies

6. Shell Programming and Scripting

Append the output data horizontally

Hi experts i have a simple script that fetches the count from different servers and inserts ahead of server name like below servera,1 serverb,25 serverc,35 what i want to do is now when i run this script next day i want that output to be next to the earlier one like below and if possible... (5 Replies)
Discussion started by: raj2989
5 Replies

7. UNIX for Dummies Questions & Answers

Output to file but append rather than overwrite?

I am running a command which has a parameter that outputs the results to a file each time it is run. Here is the command: --fullresult=true > importlog.xml Can I add the output to the file rather than creating a new one which overwrites the existing one? If not can I make the file name... (2 Replies)
Discussion started by: Sepia
2 Replies

8. Shell Programming and Scripting

How to append the output continously from a script

Hi All, Am using the below script to produce some statistics. Currently it send the results to a log file and sends the contents of the log to a mail ID. Next time when it runs it erases the previous log and writes the latest output to the log file. I want the output to be appended to... (2 Replies)
Discussion started by: nirmal84
2 Replies

9. Shell Programming and Scripting

Append Output to another file in Perl

Hi All, I am writing a Perl script such that the output from "perl myscript.pl file1" to be appended to another file name called file2. I tried out with the below code but couldn't work. Can any expert give me some advice? open(OUTPUT, 'perl myscript.pl file1 |'); close OUTPUT;... (7 Replies)
Discussion started by: Raynon
7 Replies

10. Shell Programming and Scripting

Append output to file

Hi, I have a script below. It get's the data from the output of a script that is running hourly. My problem is every time my script runs, it deletes the previous data and put the current data. Please see output below. What I would like to do is to have the hourly output to be appended on the... (3 Replies)
Discussion started by: ayhanne
3 Replies
Login or Register to Ask a Question