Help with perl script

mattg1981

Senior member
Jun 19, 2003
957
0
76
I am running a foreach loop on a list (shown below) that runs `md5sum` on every file listed in the list. However, md5sum prints out in the format [0-9a-z]+ filename ... but I need to print it out in reverse. I have tried some regex tests like:

$out = s/^[0-9a-z]+/$2 $1/g; # combining sed and awk here .. dunno if this is allowed
and I have also tried capturing the [0-9a-z]+ with braces () .. but I think I am just going about this the wrong way. Can someone help me out. Thanks

 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Your code does absolutely nothing to help me see the output format of md5sum. give me an example or two of output and I can write the regex to reverse it.

Edit: I ran the md5sum that comes with cygwin. It gave me output in this format:

7db5b41874ce7a5ca347b40aacf1c151 *aar.tar

If you run that line through this regex:

$sum =~ s/([^ ]+) (.*)/$2 $1/;

you get this:

*aar.tar 7db5b41874ce7a5ca347b40aacf1c151

Which, I assume, is what you want.


NOTE: there are two spaces in that regex. After ^, and between ) and (.
 

mattg1981

Senior member
Jun 19, 2003
957
0
76
Originally posted by: notfred
Your code does absolutely nothing to help me see the output format of md5sum. give me an example or two of output and I can write the regex to reverse it.

Edit: I ran the md5sum that comes with cygwin. It gave me output in this format:

7db5b41874ce7a5ca347b40aacf1c151 *aar.tar

If you run that line through this regex:

$sum =~ s/([^ ]+) (.*)/$2 $1/;

you get this:

*aar.tar 7db5b41874ce7a5ca347b40aacf1c151

Which, I assume, is what you want.


NOTE: there are two spaces in that regex. After ^, and between ) and (.


Oh I see .. I had my parenthesis in the wrong spots ...

btw, why would you want/need the space after the ^ ... isnt that saying "look for a space as the first character at the begginning for the line" ?
 

CyGoR

Platinum Member
Jun 23, 2001
2,017
0
0
Nope, a ^ in a character class [ ] is a negated character class, so it forbids any spaces..
[^a-z] forbids any lower case characters.
 

mattg1981

Senior member
Jun 19, 2003
957
0
76
Originally posted by: CyGoR
Nope, a ^ in a character class [ ] is a negated character class, so it forbids any spaces..
[^a-z] forbids any lower case characters.

I had no idea (must have missed that day in class), thanks for the input