0

My task is to generate MD5 checksum with filesize. I'm using "md5deep.exe" to generate checksum. For example, this is what it generates

32  6f9ded5211cf63f862f0c3c6f50d9ab6    /something.txt

First column = size, Second column - md5 checksum, last column = file name

is there anyway to switch columns? i would like md5 checksum vale in first column and file size in second column. Basically my script creates a text file.

test.txt

32  6f9ded5211cf63f862f0c3c6f50d9ab6    /something.txt
46  05c66e7d62f1bc975cc9ccb5a44b7c24    /some1.txt
2853383 2fcd0e40e2a24aaa59c412b48c4d80fa    /something2.txt

or is there any way i can switch columns using perl?

Mihir
  • 557
  • 1
  • 6
  • 28

1 Answers1

1

Is an awk solution also acceptable?

$ awk '{print $2,$1,$3}' test.txt
6f9ded5211cf63f862f0c3c6f50d9ab6 32 /something.txt
05c66e7d62f1bc975cc9ccb5a44b7c24 46 /some1.txt
2fcd0e40e2a24aaa59c412b48c4d80fa 2853383 /something2.txt

If not, you could use this perl variant:

$ perl -ane 'print "@F[1,0,2]\n"' test.txt
6f9ded5211cf63f862f0c3c6f50d9ab6 32 /something.txt
05c66e7d62f1bc975cc9ccb5a44b7c24 46 /some1.txt
2fcd0e40e2a24aaa59c412b48c4d80fa 2853383 /something2.txt
Kokkie
  • 546
  • 6
  • 15
  • Thank you very much for quick response, but i tried to use "perl -ane 'print $F[1]," ",$F[0]," ",$F[2] . "\n"' test.txt" it says "Can't find string terminator" so i tried "perl `-ane 'print $F[1]," ",$F[0]," ",$F[2] . "\n"' test.txt`;" that too didn't work. Second changes gave me following error " Can't open perl script "`-ane": No such file or directory – Mihir Jul 16 '14 at 14:28
  • What OS and version of perl are you using? At least it works on Ubuntu and using Cygwin on Windows with perl 5, version 14. – Kokkie Jul 16 '14 at 14:32
  • i'm using windows with perl version #5.8.3 build 809 – Mihir Jul 16 '14 at 14:36
  • 1
    Kokkie gave you a `sh` shell command, but you're using `cmd`. Adjust accordingly. `perl -lane"print qq{@F[1,0,2]}" test.txt` – ikegami Jul 16 '14 at 15:12
  • perl -ane "print \"@F[1,0,2]\n\"" test.txt , see http://stackoverflow.com/questions/7761057/why-am-i-getting-cant-find-string-terminator-anywhere-before-eof-at-e-lin – Kokkie Jul 16 '14 at 15:12
  • 1
    Note that that fails for file names with spaces in them. Fixed: `perl -nle"@F=split(' ', $_, 3); print qq{@F{1,0,2}" test.txt` – ikegami Jul 16 '14 at 15:13