Sed , windows and "regular expressions"

flyinghaggis

Active member
Feedback: 0 / 0 / 0
Joined
Feb 26, 2020
Messages
78
Reaction score
126
Credits
458
been awhile since I used Sed..

trying to extract hashes from a txt file in windows using the windows 10 cmd line and
I can't remember which characters to escape I have had a quick look on line but still
none the wiser - so instead i run it through vmware effective but not practical.

I am in the process of installing the windows sub system for linux but due to a heavy workload
haven't finished the setup

The command is

sed -rn 's/.*[^a-fA-F0-9]([a-fA-F0-9]{32})[^a-fA-F0-9].*/1/p' *.txt > md5-hashes

and the error is
sed.exe: -e expression #1, char 1: Unknown command: `''
I have tried escaping the `'' but still cant get it to run - any help would be appreciated
 

freeroute

Community Manager
Staff member
Community Manager
Super Moderator
Feedback: 2 / 0 / 0
Joined
Dec 30, 2019
Messages
21,139
Reaction score
1,703
Credits
9,440
Common hash algorithm with RegEx Format:

md4
(^[0-9a-fA-F]{32}$)

md5
(^[0-9a-fA-F]{32}$)

md5($pass,$salt)

(^[0-9a-fA-F]{32}\:.{1,}$)

md5($salt,$pass)
(^[0-9a-fA-F]{32}\:.{1,}$)

vBulletin <3.8.5
(^[0-9a-fA-F]{32}\:.{1,3}$)

vBulletin >3.8.5
(^[0-9a-fA-F]{32}\:\S{28,30}$)
 

flyinghaggis

Active member
Feedback: 0 / 0 / 0
Joined
Feb 26, 2020
Messages
78
Reaction score
126
Credits
458
Common hash algorithm with RegEx Format:

md5
(^[0-9a-fA-F]{32}$)
Thanks but that is not telling which character to escape for using in the windows environment..
I believe it to be the ' character in the line
sed.exe -rn 's/.*[^a-fA-F0-9]([a-fA-F0-9]{32})[^a-fA-F0-9].*/1/p' *.txt > md5-hashes
but when I add the ^ character to escape it it doesn't work i.e.

sed -rn ^'s/.*[^a-fA-F0-9]([a-fA-F0-9]{32})[^a-fA-F0-9].*/1/p^' kjhk.txt > md5-hashes.txt
the error I get is
sed.exe: -e expression #1, char 1: Unknown command: `''

 

blacknoise

New member
Feedback: 0 / 0 / 0
Joined
Feb 2, 2020
Messages
2
Reaction score
0
Credits
7
sed in Windows does not understand single quote
try using double quotes ""
it works better under Cygwin if you have to use Windows
another option is to try put command in file command.sed and invoke using
sed -f command.sed

i could post some random regex as well if that helps?
 

flyinghaggis

Active member
Feedback: 0 / 0 / 0
Joined
Feb 26, 2020
Messages
78
Reaction score
126
Credits
458
Anything would be a help thanks..
I have noticed that it does run without the ' in the line but only outputs a series of ones
 

flyinghaggis

Active member
Feedback: 0 / 0 / 0
Joined
Feb 26, 2020
Messages
78
Reaction score
126
Credits
458
Anything would be a help thanks..
I have noticed that it does run without the ' in the line but only outputs a series of ones
It's ok now - i'll just run it through kali until I can get either cygwin or windows sub system for linux
up and running - in all the years i have been on this forum i never really ever gave regular expressions
a thought usually getting the job done by other, sometimes more complicated means but HeyHo!
 
Top