I have an issue with a file that is supposed to have only 3 fields per
line, but sometimes has more, or many more!
The file has two three letter codes in positions 1 and 2, so far so
good, filed three is supposed to be a list of email addresses in the
following form;
fred@bloggs.com;joe@wheels.com;mary@home.co.uk
but what I get at tikes is;
fred@bloggs.com; joe@wheels.com; mary@home.co.uk
What I am trying to do is if HR=3 then return the address list, if NR
> 3 then concatonate the third and all remaining fields into one strip
out the spaces in the process.
Any help would be appreciated.
Rob.
|
|
0
|
|
|
|
Reply
|
rob.bradford (3)
|
8/4/2010 6:45:18 AM |
|
Tue, 03 Aug 2010 23:45:18 -0700, Rob B did cat :
> I have an issue with a file that is supposed to have only 3 fields per
> line, but sometimes has more, or many more!
>
> The file has two three letter codes in positions 1 and 2, so far so
> good, filed three is supposed to be a list of email addresses in the
> following form;
>
> fred@bloggs.com;joe@wheels.com;mary@home.co.uk
>
> but what I get at tikes is;
>
> fred@bloggs.com; joe@wheels.com; mary@home.co.uk
>
> What I am trying to do is if HR=3 then return the address list, if NR
>> 3 then concatonate the third and all remaining fields into one strip
> out the spaces in the process.
>
> Any help would be appreciated.
>
> Rob.
one simple way could go:
$ awk '{a=$1;b=$2;$1=$2="";gsub(/ /,"");print $0}' yourfile
if you don't need to save a and b for extra usage it'd go simpler:
$ awk '{$1=$2="";gsub(/ /,"");print $0}'
or even:
$ awk '{$1=$2="";gsub(/ /,"")}1'
if that doesn't fit your aims that'd be because you have other
stuff ongoing on the data, in that case you'll have to be more precise :-)
|
|
0
|
|
|
|
Reply
|
Loki
|
8/4/2010 8:06:24 AM
|
|
On 4 Aug, 09:06, Loki Harfagr <l...@thedarkdesign.free.fr.INVALID>
wrote:
> Tue, 03 Aug 2010 23:45:18 -0700, Rob B did cat=A0:
>
>
>
>
>
> > I have an issue with a file that is supposed to have only 3 fields per
> > line, but sometimes has more, or many more!
>
> > The file has two three letter codes in positions 1 and 2, so far so
> > good, filed three is supposed to be a list of email addresses in the
> > following form;
>
> > f...@bloggs.com;j...@wheels.com;m...@home.co.uk
>
> > but what I get at tikes is;
>
> > f...@bloggs.com; j...@wheels.com; m...@home.co.uk
>
> > What I am trying to do is if HR=3D3 then return the address list, if NR
> >> 3 then concatonate the third and all remaining fields into one strip
> > out the spaces in the process.
>
> > Any help would be appreciated.
>
> > Rob.
>
> =A0one simple way could go:
> $ awk '{a=3D$1;b=3D$2;$1=3D$2=3D"";gsub(/ /,"");print $0}' yourfile
>
> =A0if you don't need to save a and b for extra usage it'd go simpler:
> $ awk '{$1=3D$2=3D"";gsub(/ /,"");print $0}'
>
> =A0or even:
> $ awk '{$1=3D$2=3D"";gsub(/ /,"")}1'
>
> =A0if that doesn't fit your aims that'd be because you have other
> stuff ongoing on the data, in that case you'll have to be more precise :-=
)- Hide quoted text -
>
> - Show quoted text -
Thanks,
that has done what I need. Can you suggest any good reading to
improve my AWK skills? Other than the usual O'Reilly books.
Rob.
|
|
0
|
|
|
|
Reply
|
Rob
|
8/4/2010 8:11:17 AM
|
|
Rob B schrieb:
> I have an issue with a file that is supposed to have only 3 fields per
> line, but sometimes has more, or many more!
>
> The file has two three letter codes in positions 1 and 2, so far so
> good, filed three is supposed to be a list of email addresses in the
> following form;
>
> fred@bloggs.com;joe@wheels.com;mary@home.co.uk
>
> but what I get at tikes is;
>
> fred@bloggs.com; joe@wheels.com; mary@home.co.uk
>
> What I am trying to do is if HR=3 then return the address list, if NR
> > 3 then concatonate the third and all remaining fields into one strip
> out the spaces in the process.
awk -v OFS="" '{$1=$2=""}1'
Janis
>
> Any help would be appreciated.
>
> Rob.
|
|
0
|
|
|
|
Reply
|
Janis
|
8/4/2010 8:16:48 AM
|
|
Rob B schrieb:
> On 4 Aug, 09:06, Loki Harfagr <l...@thedarkdesign.free.fr.INVALID>
> wrote:
>> Tue, 03 Aug 2010 23:45:18 -0700, Rob B did cat :
>>
>>
>>
>>
>>
>>> I have an issue with a file that is supposed to have only 3 fields per
>>> line, but sometimes has more, or many more!
>>> The file has two three letter codes in positions 1 and 2, so far so
>>> good, filed three is supposed to be a list of email addresses in the
>>> following form;
>>> f...@bloggs.com;j...@wheels.com;m...@home.co.uk
>>> but what I get at tikes is;
>>> f...@bloggs.com; j...@wheels.com; m...@home.co.uk
>>> What I am trying to do is if HR=3 then return the address list, if NR
>>>> 3 then concatonate the third and all remaining fields into one strip
>>> out the spaces in the process.
>>> Any help would be appreciated.
>>> Rob.
>> one simple way could go:
>> $ awk '{a=$1;b=$2;$1=$2="";gsub(/ /,"");print $0}' yourfile
>>
>> if you don't need to save a and b for extra usage it'd go simpler:
>> $ awk '{$1=$2="";gsub(/ /,"");print $0}'
>>
>> or even:
>> $ awk '{$1=$2="";gsub(/ /,"")}1'
>>
>> if that doesn't fit your aims that'd be because you have other
>> stuff ongoing on the data, in that case you'll have to be more precise :-)- Hide quoted text -
>>
>> - Show quoted text -
>
> Thanks,
> that has done what I need. Can you suggest any good reading to
> improve my AWK skills? Other than the usual O'Reilly books.
Arnold Robbins: "Effective awk Programming". (Also available online.)
(Sorry, it *is* from O'Reilly.)
Janis
>
> Rob.
|
|
0
|
|
|
|
Reply
|
Janis
|
8/4/2010 8:21:02 AM
|
|
On 8/4/2010 3:21 AM, Janis Papanagnou wrote:
> Rob B schrieb:
>> On 4 Aug, 09:06, Loki Harfagr <l...@thedarkdesign.free.fr.INVALID>
>> wrote:
>>> Tue, 03 Aug 2010 23:45:18 -0700, Rob B did cat :
>>>
>>>
>>>
>>>
>>>
>>>> I have an issue with a file that is supposed to have only 3 fields per
>>>> line, but sometimes has more, or many more!
>>>> The file has two three letter codes in positions 1 and 2, so far so
>>>> good, filed three is supposed to be a list of email addresses in the
>>>> following form;
>>>> f...@bloggs.com;j...@wheels.com;m...@home.co.uk
>>>> but what I get at tikes is;
>>>> f...@bloggs.com; j...@wheels.com; m...@home.co.uk
>>>> What I am trying to do is if HR=3 then return the address list, if NR
>>>>> 3 then concatonate the third and all remaining fields into one strip
>>>> out the spaces in the process.
>>>> Any help would be appreciated.
>>>> Rob.
>>> one simple way could go:
>>> $ awk '{a=$1;b=$2;$1=$2="";gsub(/ /,"");print $0}' yourfile
>>>
>>> if you don't need to save a and b for extra usage it'd go simpler:
>>> $ awk '{$1=$2="";gsub(/ /,"");print $0}'
>>>
>>> or even:
>>> $ awk '{$1=$2="";gsub(/ /,"")}1'
>>>
>>> if that doesn't fit your aims that'd be because you have other
>>> stuff ongoing on the data, in that case you'll have to be more
>>> precise :-)- Hide quoted text -
>>>
>>> - Show quoted text -
>>
>> Thanks,
>> that has done what I need. Can you suggest any good reading to
>> improve my AWK skills? Other than the usual O'Reilly books.
>
> Arnold Robbins: "Effective awk Programming". (Also available online.)
>
and after reading that, lurk around here and try to answer the posted questions
using the book as a reference.
Ed.
|
|
0
|
|
|
|
Reply
|
Ed
|
8/4/2010 1:33:13 PM
|
|
On 4 Aug, 14:33, Ed Morton <mortons...@gmail.com> wrote:
> On 8/4/2010 3:21 AM, Janis Papanagnou wrote:
>
>
>
>
>
> > Rob B schrieb:
> >> On 4 Aug, 09:06, Loki Harfagr <l...@thedarkdesign.free.fr.INVALID>
> >> wrote:
> >>> Tue, 03 Aug 2010 23:45:18 -0700, Rob B did cat :
>
> >>>> I have an issue with a file that is supposed to have only 3 fields p=
er
> >>>> line, but sometimes has more, or many more!
> >>>> The file has two three letter codes in positions 1 and 2, so far so
> >>>> good, filed three is supposed to be a list of email addresses in the
> >>>> following form;
> >>>> f...@bloggs.com;j...@wheels.com;m...@home.co.uk
> >>>> but what I get at tikes is;
> >>>> f...@bloggs.com; j...@wheels.com; m...@home.co.uk
> >>>> What I am trying to do is if HR=3D3 then return the address list, if=
NR
> >>>>> 3 then concatonate the third and all remaining fields into one stri=
p
> >>>> out the spaces in the process.
> >>>> Any help would be appreciated.
> >>>> Rob.
> >>> one simple way could go:
> >>> $ awk '{a=3D$1;b=3D$2;$1=3D$2=3D"";gsub(/ /,"");print $0}' yourfile
>
> >>> if you don't need to save a and b for extra usage it'd go simpler:
> >>> $ awk '{$1=3D$2=3D"";gsub(/ /,"");print $0}'
>
> >>> or even:
> >>> $ awk '{$1=3D$2=3D"";gsub(/ /,"")}1'
>
> >>> if that doesn't fit your aims that'd be because you have other
> >>> stuff ongoing on the data, in that case you'll have to be more
> >>> precise :-)- Hide quoted text -
>
> >>> - Show quoted text -
>
> >> Thanks,
> >> that has done what I need. Can you suggest any good reading to
> >> improve my AWK skills? Other than the usual O'Reilly books.
>
> > Arnold Robbins: "Effective awk Programming". (Also available online.)
>
> and after reading that, lurk around here and try to answer the posted que=
stions
> using the book as a reference.
>
> =A0 =A0 =A0 =A0 Ed.- Hide quoted text -
>
> - Show quoted text -
Thanks every one, although it's been a bit of a while since I did any
"lurking".
Rob.B
|
|
0
|
|
|
|
Reply
|
Rob
|
8/4/2010 2:08:26 PM
|
|
|
6 Replies
101 Views
(page loaded in 0.075 seconds)
|