* Changes in file (huge problem)
@ 2006-12-24 13:51 Mário Gamito
2006-12-24 22:23 ` Glynn Clements
2006-12-25 10:25 ` terry white
0 siblings, 2 replies; 6+ messages in thread
From: Mário Gamito @ 2006-12-24 13:51 UTC (permalink / raw)
To: linux-admin
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
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 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
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 majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Changes in file (huge problem)
2006-12-24 13:51 Changes in file (huge problem) Mário Gamito
@ 2006-12-24 22:23 ` Glynn Clements
2006-12-24 23:31 ` Mário Gamito
2006-12-25 10:25 ` terry white
1 sibling, 1 reply; 6+ messages in thread
From: Glynn Clements @ 2006-12-24 22:23 UTC (permalink / raw)
To: Mário Gamito; +Cc: linux-admin
Mário Gamito wrote:
> 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 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:/
--
Glynn Clements <glynn@gclements.plus.com>
-
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Changes in file (huge problem)
2006-12-24 22:23 ` Glynn Clements
@ 2006-12-24 23:31 ` Mário Gamito
2006-12-26 23:48 ` Glynn Clements
0 siblings, 1 reply; 6+ messages in thread
From: Mário Gamito @ 2006-12-24 23:31 UTC (permalink / raw)
To: Glynn Clements; +Cc: linux-admin
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
Glynn Clements wrote:
> Mário Gamito wrote:
>
>> 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 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:/
>
-
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Changes in file (huge problem)
2006-12-24 13:51 Changes in file (huge problem) Mário Gamito
2006-12-24 22:23 ` Glynn Clements
@ 2006-12-25 10:25 ` terry white
2006-12-25 19:09 ` Mário Gamito
1 sibling, 1 reply; 6+ messages in thread
From: terry white @ 2006-12-25 10:25 UTC (permalink / raw)
To: linux-admin
... 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:foo@foo.foo" >> $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:foo@foo.foo" >> $DST
fi
fi
done
exit
===== end code =====
--
... 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Changes in file (huge problem)
2006-12-25 10:25 ` terry white
@ 2006-12-25 19:09 ` Mário Gamito
0 siblings, 0 replies; 6+ messages in thread
From: Mário Gamito @ 2006-12-25 19:09 UTC (permalink / raw)
To: terry white; +Cc: linux-admin
Hi Terry,
Thank you so much for your answer.
It really did the trick :-)
terry white wrote:
> ... 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 majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Changes in file (huge problem)
2006-12-24 23:31 ` Mário Gamito
@ 2006-12-26 23:48 ` Glynn Clements
0 siblings, 0 replies; 6+ messages in thread
From: Glynn Clements @ 2006-12-26 23:48 UTC (permalink / raw)
To: Mário Gamito; +Cc: linux-admin
Mário 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@gclements.plus.com>
-
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-12-26 23:48 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-24 13:51 Changes in file (huge problem) Mário Gamito
2006-12-24 22:23 ` Glynn Clements
2006-12-24 23:31 ` Mário Gamito
2006-12-26 23:48 ` Glynn Clements
2006-12-25 10:25 ` terry white
2006-12-25 19:09 ` Mário Gamito
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).