Changes in file (huge problem)

Hi,

I have this file in the following format:

tarta 16340309 marsanpin brigittamario [at] xxx.pt
lms doom123 Luis Miguel Sequeira lms [at] xxx.pt
jura teste Juraci jgweb [at] bol.com.br
jsilva t00lt0ya5 Jorge Silva jsilva [at] xxx.com
tchock mail#4829 tchock engDias [at] xxx.pt
reporterx noname Duarte Oliveira mtbf99 [at] 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
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 [at] 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
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 [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
gamito [ So, 24 Dezember 2006 14:51 ] [ ID #1576588 ]

Re: Changes in file (huge problem)

M=E1rio Gamito wrote:

> I have this file in the following format:
>
> tarta 16340309 marsanpin brigittamario [at] xxx.pt
> lms doom123 Luis Miguel Sequeira lms [at] xxx.pt
> jura teste Juraci jgweb [at] bol.com.br
> jsilva t00lt0ya5 Jorge Silva jsilva [at] xxx.com
> tchock mail#4829 tchock engDias [at] xxx.pt
> reporterx noname Duarte Oliveira mtbf99 [at] 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 unk=
now
> 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 n=
ame.

#!/usr/bin/sed -f
s/^\([^ ]\+\) \+\([^ ]\+\) \+\(.\+\) \+\([^ [at] ]\+ [at] [^ [at] ]\+\) *$/\1:\2:\3:=
\4/
s/^\([^ ]\+\) \+\([^ ]\+\) \+\([^ [at] ]\+ [at] [^ [at] ]\+\) *$/\1:\2::\3/
s/^\([^ ]\+\) \+\([^ ]\+\) \+\(.\+\) *$/\1:\2:\3:/

--
Glynn Clements <glynn [at] gclements.plus.com>
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" =
in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Glynn Clements [ So, 24 Dezember 2006 23:23 ] [ ID #1576589 ]

Re: Changes in file (huge problem)

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:
>
>> I have this file in the following format:
>>
>> tarta 16340309 marsanpin brigittamario [at] xxx.pt
>> lms doom123 Luis Miguel Sequeira lms [at] xxx.pt
>> jura teste Juraci jgweb [at] bol.com.br
>> jsilva t00lt0ya5 Jorge Silva jsilva [at] xxx.com
>> tchock mail#4829 tchock engDias [at] xxx.pt
>> reporterx noname Duarte Oliveira mtbf99 [at] 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
>> 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/^\([^ ]\+\) \+\([^ ]\+\) \+\(.\+\) \+\([^ [at] ]\+ [at] [^ [at] ]\+\) *$/\1:\2:\=
3:\4/
> s/^\([^ ]\+\) \+\([^ ]\+\) \+\([^ [at] ]\+ [at] [^ [at] ]\+\) *$/\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 majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
gamito [ Mo, 25 Dezember 2006 00:31 ] [ ID #1577013 ]

Re: Changes in file (huge problem)

=2E.. 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=3D=3D=3D=3D start code =3D=3D=3D=3D=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 [at] 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 " [at] "` ]
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 [at] foo.foo" >> $DST
fi

fi
done

exit


=3D=3D=3D=3D=3D end code =3D=3D=3D=3D=3D



--
=2E.. 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 [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
terry white [ Mo, 25 Dezember 2006 11:25 ] [ ID #1577014 ]

Re: Changes in file (huge problem)

Hi Terry,

Thank you so much for your answer.
It really did the trick :-)

terry white wrote:
> ... 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.
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 [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
gamito [ Mo, 25 Dezember 2006 20:09 ] [ ID #1577015 ]

Re: Changes in file (huge problem)

M=E1rio Gamito wrote:

> 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 ?

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

--
Glynn Clements <glynn [at] gclements.plus.com>
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" =
in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Glynn Clements [ Mi, 27 Dezember 2006 00:48 ] [ ID #1578031 ]
Linux » gmane.linux.admin » Changes in file (huge problem)

Vorheriges Thema: FW:
Nächstes Thema: Aiee, killing interrupt handler!