You are not logged in.
I'm new to scripting and was wondering if anyone had some pointers for me. I have a text file in the following format:
"user1@email.com" TAB "password1"
"user2@email.com" TAB "password2"
That "TAB" is an actual tab of course. I need the file to output like this:
user1@email.com,user1@email.com,password1
user2@email.com,user2@email.com,password2
Any suggestions?
Offline
cat myfile | awk '{ print $1 "," $1 "," $2 }'Go, awk, go! (I love how abused awk is...)
Offline
Here's another option, to be verbose:
fmt () { echo "$1,$1,$2"; }
while read line; do
fmt $line
done < my_text_file;Offline
sed -r 's|(.*)t(.*)|1,1,2|'1000
Offline
Thanks guys. The first one worked for me. awk is pretty sweet
Offline
Ok. How about this:
drpepper@email.com,drpepper@email.com,password,64.227.239.141
Into this:
drpepper@email.com,drpepper@email.com,password,64.227.239.141,drpepper
Any ideas? I'm trying to learn this for an Exchange migration script if anyone was wondering.
Offline
I would use sed for that one, similar to what byte did... I don't want to give away too much because you said you wanted to learn it.
The idea is that sed maintaines regex matches with () (or () is -r is not specified), which are used in the second expression. You can also nest these parenthesis.
Here, I'll give you an example to work with:
echo "drpepper@email.com" | sed -r "s|(([^@]*).*)|1,2|"Offline
Thanks phrakture. I'll have to play with this. A coworker came up with this:
cat email.txt | awk -F@ '{print $1"@"$2"@"$3","$1}' > emaildone.txt
Awk seems a little easier with beginners. I would also like to learn a little about sed too.
Offline
I would also like to learn a little about sed too.
http://www.cornerstonemag.com/sed/ should have links enough and you're welcome to bug me ('jra') on irc://chat.freenode.net/#archlinux for hints.
1000
Offline
Thanks phrakture. I'll have to play with this. A coworker came up with this:
cat email.txt | awk -F@ '{print $1"@"$2"@"$3","$1}' > emaildone.txt
Awk seems a little easier with beginners. I would also like to learn a little about sed too.
Heh, that's rather interesting, splitting on the @ sign. I like it.
Awk is easier to get the basics of, but awk itself can get real complicated real fast. Awk, is, in fact, a full programming language.
Offline
I have to give credit to Dale the package maintainer for it. It's his work of art. Thanks to you too byte.
Offline