An Alternative Way?
am 24.10.2007 15:46:12 von mostro713
Hi all,
I looking for an alternate way to manipulate a file. The file contains
a list of members email addresses in the format of "domain\name"
For example:
abc.com\john
abc.com\robert
abc.com\mike
abc.com\nancy
abc.com\beth
abc.com\mary
What I would like to do is turn this file into john@abc.com,
robert@abc.com, etc...
This is what I have come up with so far. There has to be a way to do
this on one line.
cat member.txt |cut -d, -f1 |sed 's/\\/ /g'| cut -d" " -f2 >
secondhalf
cat member.txt |cut -d, -f1 |sed 's/\\/ /g'| cut -d" " -f1 > firsthalf
paste -d" " secondhalf firsthalf | sed 's/ /\@/g' >
properemailaddresses
P.S. The the file had a lot more fields hence the reason for the cuts
(f2, f1).
Any ideas?
Thanks in advance
Re: An Alternative Way?
am 24.10.2007 16:09:12 von Janis Papanagnou
mostro713@gmail.com wrote:
> Hi all,
>
> I looking for an alternate way to manipulate a file. The file contains
> a list of members email addresses in the format of "domain\name"
>
> For example:
>
> abc.com\john
> abc.com\robert
> abc.com\mike
> abc.com\nancy
> abc.com\beth
> abc.com\mary
>
> What I would like to do is turn this file into john@abc.com,
> robert@abc.com, etc...
All output comma separated in one line, or each address in an own line?
>
> This is what I have come up with so far. There has to be a way to do
> this on one line.
>
> cat member.txt |cut -d, -f1 |sed 's/\\/ /g'| cut -d" " -f2 >
> secondhalf
> cat member.txt |cut -d, -f1 |sed 's/\\/ /g'| cut -d" " -f1 > firsthalf
> paste -d" " secondhalf firsthalf | sed 's/ /\@/g' >
> properemailaddresses
>
> P.S. The the file had a lot more fields hence the reason for the cuts
> (f2, f1).
>
> Any ideas?
Here's a solution...
awk 'BEGIN{FS="\\";OFS="@"}{print $2,$1}' member.txt
Janis
>
> Thanks in advance
>
Re: An Alternative Way?
am 24.10.2007 17:10:02 von Ed Morton
Janis Papanagnou wrote:
> mostro713@gmail.com wrote:
>
>> Hi all,
>>
>> I looking for an alternate way to manipulate a file. The file contains
>> a list of members email addresses in the format of "domain\name"
>>
>> For example:
>>
>> abc.com\john
>> abc.com\robert
>> abc.com\mike
>> abc.com\nancy
>> abc.com\beth
>> abc.com\mary
>>
>> What I would like to do is turn this file into john@abc.com,
>> robert@abc.com, etc...
>
>
> All output comma separated in one line, or each address in an own line?
>
>>
>> This is what I have come up with so far. There has to be a way to do
>> this on one line.
>>
>> cat member.txt |cut -d, -f1 |sed 's/\\/ /g'| cut -d" " -f2 >
>> secondhalf
>> cat member.txt |cut -d, -f1 |sed 's/\\/ /g'| cut -d" " -f1 > firsthalf
>> paste -d" " secondhalf firsthalf | sed 's/ /\@/g' >
>> properemailaddresses
>>
>> P.S. The the file had a lot more fields hence the reason for the cuts
>> (f2, f1).
>>
>> Any ideas?
>
>
> Here's a solution...
>
> awk 'BEGIN{FS="\\";OFS="@"}{print $2,$1}' member.txt
>
The OP wanted the output comma-separated:
awk -F\\ '{printf "%s%s@%s",s,$2,$1;s=", "}END{print ""}' member.txt
Ed.
Re: An Alternative Way?
am 24.10.2007 18:25:52 von Janis Papanagnou
Ed Morton wrote:
> Janis Papanagnou wrote:
>
>> mostro713@gmail.com wrote:
>>
>>> Hi all,
>>>
>>> I looking for an alternate way to manipulate a file. The file contains
>>> a list of members email addresses in the format of "domain\name"
>>>
>>> For example:
>>>
>>> abc.com\john
>>> abc.com\robert
>>> abc.com\mike
>>> abc.com\nancy
>>> abc.com\beth
>>> abc.com\mary
>>>
>>> What I would like to do is turn this file into john@abc.com,
>>> robert@abc.com, etc...
>>
>>
>>
>> All output comma separated in one line, or each address in an own line?
>>
>>>
>>> This is what I have come up with so far. There has to be a way to do
>>> this on one line.
>>>
>>> cat member.txt |cut -d, -f1 |sed 's/\\/ /g'| cut -d" " -f2 >
>>> secondhalf
>>> cat member.txt |cut -d, -f1 |sed 's/\\/ /g'| cut -d" " -f1 > firsthalf
>>> paste -d" " secondhalf firsthalf | sed 's/ /\@/g' >
>>> properemailaddresses
>>>
>>> P.S. The the file had a lot more fields hence the reason for the cuts
>>> (f2, f1).
>>>
>>> Any ideas?
>>
>>
>>
>> Here's a solution...
>>
>> awk 'BEGIN{FS="\\";OFS="@"}{print $2,$1}' member.txt
>>
>
> The OP wanted the output comma-separated:
I asked above, whether he wanted it in a single line, or whether it
was just a list to show how each individual entry (per line) shall be
constructed.
But the OP's own 3-line code seems to indicate that he wants it _one
entry per line_.
Janis
>
> awk -F\\ '{printf "%s%s@%s",s,$2,$1;s=", "}END{print ""}' member.txt
>
> Ed.
>
Re: An Alternative Way?
am 24.10.2007 18:34:08 von Bill Marcum
On 2007-10-24, mostro713@gmail.com wrote:
> Hi all,
>
> I looking for an alternate way to manipulate a file. The file contains
> a list of members email addresses in the format of "domain\name"
>
> For example:
>
> abc.com\john
> abc.com\robert
> abc.com\mike
> abc.com\nancy
> abc.com\beth
> abc.com\mary
>
> What I would like to do is turn this file into john@abc.com,
> robert@abc.com, etc...
>
> This is what I have come up with so far. There has to be a way to do
> this on one line.
>
> cat member.txt |cut -d, -f1 |sed 's/\\/ /g'| cut -d" " -f2 >
> secondhalf
> cat member.txt |cut -d, -f1 |sed 's/\\/ /g'| cut -d" " -f1 > firsthalf
> paste -d" " secondhalf firsthalf | sed 's/ /\@/g' >
> properemailaddresses
>
sed 's|.*,\(.*\)/\(.*\)|\2@\1|' member.txt > properemailaddresses
> P.S. The the file had a lot more fields hence the reason for the cuts
> (f2, f1).
>
> Any ideas?
>
> Thanks in advance
>
Re: An Alternative Way?
am 24.10.2007 19:06:01 von mostro713
Hi guys,
To answer the question above each entry should stay on its own line. I
will try the solutions above... Cool
Thanks
On Oct 24, 12:34 pm, Bill Marcum wrote:
> On 2007-10-24, mostro...@gmail.com wrote:
>
> > Hi all,
>
> > I looking for an alternate way to manipulate a file. The file contains
> > a list of members email addresses in the format of "domain\name"
>
> > For example:
>
> > abc.com\john
> > abc.com\robert
> > abc.com\mike
> > abc.com\nancy
> > abc.com\beth
> > abc.com\mary
>
> > What I would like to do is turn this file into j...@abc.com,
> > rob...@abc.com, etc...
>
> > This is what I have come up with so far. There has to be a way to do
> > this on one line.
>
> > cat member.txt |cut -d, -f1 |sed 's/\\/ /g'| cut -d" " -f2 >
> > secondhalf
> > cat member.txt |cut -d, -f1 |sed 's/\\/ /g'| cut -d" " -f1 > firsthalf
> > paste -d" " secondhalf firsthalf | sed 's/ /\@/g' >
> > properemailaddresses
>
> sed 's|.*,\(.*\)/\(.*\)|\2@\1|' member.txt > properemailaddresses
>
> > P.S. The the file had a lot more fields hence the reason for the cuts
> > (f2, f1).
>
> > Any ideas?
>
> > Thanks in advance
Re: An Alternative Way?
am 24.10.2007 19:25:51 von mostro713
On Oct 24, 1:06 pm, "mostro...@gmail.com" wrote:
> Hi guys,
>
> To answer the question above each entry should stay on its own line. I
> will try the solutions above... Cool
>
> Thanks
>
> On Oct 24, 12:34 pm, Bill Marcum wrote:
>
> > On 2007-10-24, mostro...@gmail.com wrote:
>
> > > Hi all,
>
> > > I looking for an alternate way to manipulate a file. The file contains
> > > a list of members email addresses in the format of "domain\name"
>
> > > For example:
>
> > > abc.com\john
> > > abc.com\robert
> > > abc.com\mike
> > > abc.com\nancy
> > > abc.com\beth
> > > abc.com\mary
>
> > > What I would like to do is turn this file into j...@abc.com,
> > > rob...@abc.com, etc...
>
> > > This is what I have come up with so far. There has to be a way to do
> > > this on one line.
>
> > > cat member.txt |cut -d, -f1 |sed 's/\\/ /g'| cut -d" " -f2 >
> > > secondhalf
> > > cat member.txt |cut -d, -f1 |sed 's/\\/ /g'| cut -d" " -f1 > firsthalf
> > > paste -d" " secondhalf firsthalf | sed 's/ /\@/g' >
> > > properemailaddresses
>
> > sed 's|.*,\(.*\)/\(.*\)|\2@\1|' member.txt > properemailaddresses
>
> > > P.S. The the file had a lot more fields hence the reason for the cuts
> > > (f2, f1).
>
> > > Any ideas?
>
> > > Thanks in advance
Here is what worked for me....
cat member.txt |awk -F\\ '{printf "%s%s@%s",s,$2,$1;s="\n"}END{print
""}' member1.txt
I added the \n for the string constant. Now I have to read the man
page for Awk to interpret that statement. :)
Thank you for the help...
Re: An Alternative Way?
am 24.10.2007 19:56:11 von Michael Tosch
mostro713@gmail.com wrote:
> On Oct 24, 1:06 pm, "mostro...@gmail.com" wrote:
>> Hi guys,
>>
>> To answer the question above each entry should stay on its own line. I
>> will try the solutions above... Cool
>>
>> Thanks
>>
>> On Oct 24, 12:34 pm, Bill Marcum wrote:
>>
>>> On 2007-10-24, mostro...@gmail.com wrote:
>>>> Hi all,
>>>> I looking for an alternate way to manipulate a file. The file contains
>>>> a list of members email addresses in the format of "domain\name"
>>>> For example:
>>>> abc.com\john
>>>> abc.com\robert
>>>> abc.com\mike
>>>> abc.com\nancy
>>>> abc.com\beth
>>>> abc.com\mary
>>>> What I would like to do is turn this file into j...@abc.com,
>>>> rob...@abc.com, etc...
>>>> This is what I have come up with so far. There has to be a way to do
>>>> this on one line.
>>>> cat member.txt |cut -d, -f1 |sed 's/\\/ /g'| cut -d" " -f2 >
>>>> secondhalf
>>>> cat member.txt |cut -d, -f1 |sed 's/\\/ /g'| cut -d" " -f1 > firsthalf
>>>> paste -d" " secondhalf firsthalf | sed 's/ /\@/g' >
>>>> properemailaddresses
>>> sed 's|.*,\(.*\)/\(.*\)|\2@\1|' member.txt > properemailaddresses
>>>> P.S. The the file had a lot more fields hence the reason for the cuts
>>>> (f2, f1).
>>>> Any ideas?
>>>> Thanks in advance
>
> Here is what worked for me....
>
> cat member.txt |awk -F\\ '{printf "%s%s@%s",s,$2,$1;s="\n"}END{print
> ""}' member1.txt
>
> I added the \n for the string constant. Now I have to read the man
> page for Awk to interpret that statement. :)
>
> Thank you for the help...
>
>
This seems pretty much the same as
awk 'BEGIN{FS="\\";OFS="@"}{print $2,$1}' member.txt
as s.o. else has already suggested.
I would write it as
awk -F\\ '{print $2"@"$1}' member.txt
--
Michael Tosch @ hp : com
Re: An Alternative Way?
am 24.10.2007 23:19:14 von Martien Verbruggen
On Wed, 24 Oct 2007 16:09:12 +0200,
Janis Papanagnou wrote:
> mostro713@gmail.com wrote:
>> Hi all,
>>
>> I looking for an alternate way to manipulate a file. The file contains
>> a list of members email addresses in the format of "domain\name"
>>
>> For example:
>>
>> abc.com\john
>> abc.com\robert
>> abc.com\mike
>> abc.com\nancy
>> abc.com\beth
>> abc.com\mary
>>
>> What I would like to do is turn this file into john@abc.com,
>> robert@abc.com, etc...
>
> All output comma separated in one line, or each address in an own line?
>> Any ideas?
>
> Here's a solution...
>
> awk 'BEGIN{FS="\\";OFS="@"}{print $2,$1}' member.txt
Although we now know the OP doesn't want a comma-sepaated list, it's
easy enough to change the above to produce one, by using ORS:
awk 'BEGIN{ FS="\\"; OFS="@"; ORS="," }{ print $2, $1 }' member.txt
Martien
--
|
Martien Verbruggen | Failure is not an option. It comes bundled
| with your Microsoft product.
|
Re: An Alternative Way?
am 24.10.2007 23:41:06 von Janis Papanagnou
Martien Verbruggen wrote:
> On Wed, 24 Oct 2007 16:09:12 +0200,
> Janis Papanagnou wrote:
>
>>mostro713@gmail.com wrote:
>>
>>>Hi all,
>>>
>>>I looking for an alternate way to manipulate a file. The file contains
>>>a list of members email addresses in the format of "domain\name"
>>>
>>>For example:
>>>
>>>abc.com\john
>>>abc.com\robert
>>>abc.com\mike
>>>abc.com\nancy
>>>abc.com\beth
>>>abc.com\mary
>>>
>>>What I would like to do is turn this file into john@abc.com,
>>>robert@abc.com, etc...
>>
>>All output comma separated in one line, or each address in an own line?
>
>
>>>Any ideas?
>>
>>Here's a solution...
>>
>> awk 'BEGIN{FS="\\";OFS="@"}{print $2,$1}' member.txt
>
>
> Although we now know the OP doesn't want a comma-sepaated list, it's
> easy enough to change the above to produce one, by using ORS:
Not quite; the subsequent code will produce a superfluous "," at the
end that you will have to remove. Ed already proposed a solution that
considers the final comma and it will also create a line termination.
Janis
>
> awk 'BEGIN{ FS="\\"; OFS="@"; ORS="," }{ print $2, $1 }' member.txt
>
> Martien