Changes in file (huge problem)
Changes in file (huge problem)
am 24.12.2006 14:51:06 von gamito
Hi,
I have this file in the following format:
tarta 16340309 marsanpin brigittamario@xxx.pt
lms doom123 Luis Miguel Sequeira lms@xxx.pt
jura teste Juraci jgweb@bol.com.br
jsilva t00lt0ya5 Jorge Silva jsilva@xxx.com
tchock mail#4829 tchock engDias@xxx.pt
reporterx noname Duarte Oliveira mtbf99@xxx.com
erkulix brunoverab4 Bruno Cruz
=46irst 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 unkno=
w=20
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 foo@foo.foo 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=20
field.
Substitute spaces for ":", *except* of course the spaces within the nam=
e.
I know how to do some of these things, others i don't.
Can someone help me, please ?
Thanks in advance.
Warm Regards,
M=E1rio Gamito
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" =
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: Changes in file (huge problem)
am 24.12.2006 23:23:21 von Glynn Clements
M=E1rio Gamito wrote:
> I have this file in the following format:
>=20
> tarta 16340309 marsanpin brigittamario@xxx.pt
> lms doom123 Luis Miguel Sequeira lms@xxx.pt
> jura teste Juraci jgweb@bol.com.br
> jsilva t00lt0ya5 Jorge Silva jsilva@xxx.com
> tchock mail#4829 tchock engDias@xxx.pt
> reporterx noname Duarte Oliveira mtbf99@xxx.com
> erkulix brunoverab4 Bruno Cruz
>=20
> First field is a username;
> Second field is a password in clear text;
> *Last field is the email;
> The field between is the name.
>=20
> As you can see, some lines don't have the name, and names have an unk=
now=20
> number of words.
> Some lines don't have the e-mail.
>=20
> What i need is:
> Substitute spaces for ":", *except* of course the spaces within the n=
ame.
#!/usr/bin/sed -f
s/^\([^ ]\+\) \+\([^ ]\+\) \+\(.\+\) \+\([^ @]\+@[^ @]\+\) *$/\1:\2:\3:=
\4/
s/^\([^ ]\+\) \+\([^ ]\+\) \+\([^ @]\+@[^ @]\+\) *$/\1:\2::\3/
s/^\([^ ]\+\) \+\([^ ]\+\) \+\(.\+\) *$/\1:\2:\3:/
--=20
Glynn Clements
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" =
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: Changes in file (huge problem)
am 25.12.2006 00:31:24 von gamito
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=E1rio Gamito
Glynn Clements wrote:
> M=E1rio Gamito wrote:
>=20
>> I have this file in the following format:
>>
>> tarta 16340309 marsanpin brigittamario@xxx.pt
>> lms doom123 Luis Miguel Sequeira lms@xxx.pt
>> jura teste Juraci jgweb@bol.com.br
>> jsilva t00lt0ya5 Jorge Silva jsilva@xxx.com
>> tchock mail#4829 tchock engDias@xxx.pt
>> reporterx noname Duarte Oliveira mtbf99@xxx.com
>> 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 un=
know=20
>> number of words.
>> Some lines don't have the e-mail.
>>
>> What i need is:
>=20
>> Substitute spaces for ":", *except* of course the spaces within the =
name.
>=20
> #!/usr/bin/sed -f
> s/^\([^ ]\+\) \+\([^ ]\+\) \+\(.\+\) \+\([^ @]\+@[^ @]\+\) *$/\1:\2:\=
3:\4/
> s/^\([^ ]\+\) \+\([^ ]\+\) \+\([^ @]\+@[^ @]\+\) *$/\1:\2::\3/
> s/^\([^ ]\+\) \+\([^ ]\+\) \+\(.\+\) *$/\1:\2:\3:/
>=20
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" =
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: Changes in file (huge problem)
am 25.12.2006 11:25:22 von terry white
.. ciao:
: on "12-24-2006" "M=E1rio 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.
=====3D start code =====3D
#!/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=3D"source"
DST=3D"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=3D"*******"
echo -n "$MD5:" >> $DST
# test for name or email
if [ "$REMAINDER" =3D "" ]
then echo "NO_NAME:foo@foo.foo" >> $DST
continue
# snag email and/or name
else NAME=3D""
MAIL=3D""
for T in `echo "$REMAINDER"`
do if [ `echo "$T" | fgrep -v "@"` ]
then NAME=3D"$NAME $T" # <---- adds space
else MAIL=3D"$T"
fi
done
# finish up
if [ "$NAME" =3D "" ]
then NAME=3D"NO_NAME"
fi
NAME=3D`echo "$NAME" | cut -d " " -f 2-` # <---- consumes it
if [ "$MAIL" !=3D "" ]
then echo "$NAME:$MAIL" >> $DST
else echo "$NAME:foo@foo.foo" >> $DST
fi
fi
done
exit
=====3D end code =====3D
--=20
.. 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 majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: Changes in file (huge problem)
am 25.12.2006 20:09:39 von gamito
Hi Terry,
Thank you so much for your answer.
It really did the trick :-)
terry white wrote:
> ... ciao:
>=20
> : on "12-24-2006" "M=E1rio Gamito" writ:
> : Change the second field to the correspondent md5 hash.
>=20
> 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=3D`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=E1rio Gamito
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" =
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: Changes in file (huge problem)
am 27.12.2006 00:48:17 von Glynn Clements
M=E1rio Gamito wrote:
> Thank you so much for your answer.
>=20
> I've used your code in a script and run:
> # cat passwords.sql | your_script
>=20
> but all i get is a file named typescrypt with this content:
> Script started on Sun Dec 24 23:24:28 2006
>=20
> What 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
--=20
Glynn Clements
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" =
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html