Changes in file (huge problem)
Hi,
I have this file in the following format:
tarta 16340309 marsanpin [email protected]
lms doom123 Luis Miguel Sequeira [email protected]
jura teste Juraci [email protected]
jsilva t00lt0ya5 Jorge Silva [email protected]
tchock mail#4829 tchock [email protected]
reporterx noname Duarte Oliveira [email protected]
erkulix brunoverab4 Bruno Cruz
First field is a username;
Second field is a password in clear text;
*Last field is the email;
The field between is the name.
As you can see, some lines don't have the name, and names have an unknow number of words. Some lines don't have the e-mail.
What i need is:
Change the second field to the correspondent md5 hash.
Insert [email protected] in the end of the lines that have no email. Insert the string "NO_NAME" in the ones that don't have a name in it's field. Substitute spaces for ":", *except* of course the spaces within the name.
I know how to do some of these things, others i don't.
Can someone help me, please ?
Thanks in advance.
Warm Regards,
Mário Gamito
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 15 lines · Mário Gamito
I have this file in the following format:
tarta 16340309 marsanpin [email protected] lms doom123 Luis Miguel Sequeira [email protected] jura teste Juraci [email protected] jsilva t00lt0ya5 Jorge Silva [email protected] tchock mail#4829 tchock [email protected] reporterx noname Duarte Oliveira [email protected] erkulix brunoverab4 Bruno Cruz
First field is a username;
Second field is a password in clear text; *Last field is the email;
The field between is the name.
Quoted 7 lines
As you can see, some lines don't have the name, and names have an unknow number of words.
Some lines don't have the e-mail.What i need is:
Substitute spaces for ":", *except* of course the spaces within the name.
#!/usr/bin/sed -f
s/^\([^ ]\+\) \+\([^ ]\+\) \+\(.\+\) \+\([^ @]\+@[^ @]\+\) *$/\1:\2:\3:\4/ s/^\([^ ]\+\) \+\([^ ]\+\) \+\([^ @]\+@[^ @]\+\) *$/\1:\2::\3/ s/^\([^ ]\+\) \+\([^ ]\+\) \+\(.\+\) *$/\1:\2:\3:/
Signature · 5 lines
Glynn Clements <[email protected]> - To unsubscribe from this list: send the line "unsubscribe linux-admin" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Glynn,
Thank you so much for your answer.
I've used your code in a script and run:
# cat passwords.sql | your_script
but all i get is a file named typescrypt with this content:
Script started on Sun Dec 24 23:24:28 2006
What am i doing wrong ?
Warm Regards,
Mário Gamito
Quoted 20 lines · Glynn Clements
Quoted 18 lines · Mário Gamito
I have this file in the following format:
tarta 16340309 marsanpin [email protected]
lms doom123 Luis Miguel Sequeira [email protected]
jura teste Juraci [email protected]
jsilva t00lt0ya5 Jorge Silva [email protected]
tchock mail#4829 tchock [email protected]
reporterx noname Duarte Oliveira [email protected]
erkulix brunoverab4 Bruno CruzFirst field is a username;
Second field is a password in clear text;
*Last field is the email;
The field between is the name.As you can see, some lines don't have the name, and names have an unknow number of words. Some lines don't have the e-mail.
Quoted 9 lines
Quoted 3 lines
What i need is:
Substitute spaces for ":", *except* of course the spaces within the name.
#!/usr/bin/sed -f
s/^\([^ ]\+\) \+\([^ ]\+\) \+\(.\+\) \+\([^ @]\+@[^ @]\+\) *$/\1:\2:\3:\4/ s/^\([^ ]\+\) \+\([^ ]\+\) \+\([^ @]\+@[^ @]\+\) *$/\1:\2::\3/ s/^\([^ ]\+\) \+\([^ ]\+\) \+\(.\+\) *$/\1:\2:\3:/
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · Mário Gamito
Thank you so much for your answer.
I've used your code in a script and run:
# cat passwords.sql | your_scriptbut all i get is a file named typescrypt with this content:
Script started on Sun Dec 24 23:24:28 2006What am i doing wrong ?
Did you call my script "script" by any chance?
If you run:
cat passwords.sql | script
It will run /usr/bin/script (which logs a terminal session to a file typically named "typescript").
If the script is in the current directory, you would need to use e.g.:
cat passwords.sql | ./script
or:
./script < passwords.sql
Also, it needs the execute bit set ("chmod +x") to be run directly; you can also call sed explicitly e.g.:
sed -f script < passwords.sql
Signature · 5 lines
Glynn Clements <[email protected]> - To unsubscribe from this list: send the line "unsubscribe linux-admin" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
... ciao:
: on "12-24-2006" "Mário Gamito" writ:
: Change the second field to the correspondent md5 hash.
i have no idea how to do that, so it's left to the reader.
===== start code =====
#!/bin/sh
#########################################
# 4 fields maximun, 2 mandatory #
#########################################
# 1 user
# 2 password
# 3 if exist , can be 'name' or 'email'
# 4 if exist is 'email'
# files: edit to taste
SRC="source"
DST="destination"
# let's read it
cat $SRC | \
while read USER PASSWORD REMAINDER ; do
# process user
echo -n $USER: >> $DST
# YOUR password md5 hash code goes bere
MD5="*******"
echo -n "$MD5:" >> $DST
# test for name or email
if [ "$REMAINDER" = "" ]
then echo "NO_NAME:[email protected]" >> $DST
continue
# snag email and/or name
else NAME=""
MAIL=""
for T in `echo "$REMAINDER"`
do if [ `echo "$T" | fgrep -v "@"` ]
then NAME="$NAME $T" # <---- adds space
else MAIL="$T"
fi
done# finish up
if [ "$NAME" = "" ]
then NAME="NO_NAME"
fi
NAME=echo "$NAME" | cut -d " " -f 2- # <---- consumes it
if [ "$MAIL" != "" ]
then echo "$NAME:$MAIL" >> $DST
else echo "$NAME:[email protected]" >> $DST
fi
fi
done
exit
===== end code =====
Signature · 7 lines
... i'm a man, but i can change,
if i have to , i guess ...
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.htmlHi Terry,
Thank you so much for your answer.
It really did the trick :-)
Quoted 6 lines · terry white
... ciao:
: on "12-24-2006" "Mário Gamito" writ:
: Change the second field to the correspondent md5 hash.i have no idea how to do that, so it's left to the reader.
In exchange for your info here's this one:
MD5=md5 -s "$PASSWORD" | cut -f4 -d' '
Lucky me that i am in FreeBSD.
BSD's md5 has the "-s" option to hash a string instead of a file.
Linux's md5sum doesn't.
It would require a little more hocus pocus :P
Warm Regards,
Mário Gamito
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html