From: Janis Papanagnou on
Ed Morton wrote:
> On 6/20/2010 2:56 AM, Janis Papanagnou wrote:
>> Lao Ming wrote:
>>> I have a collection of files of all ascii data in which certain lines
>>> contain an @ char. In the lines that don't have the @ char, I want to
>>> substitute a space. However, since the @ is not at the beginning or
>>> end of the line, I am having difficulty determining how to accomplish
>>> this.
>>>
>>> The data below is not the real data but it is a simple accurate
>>> example of what I want to do.
>>>
>>> 1988 G. H. W. Bush more data
>>> 1992 @Bill Clinton more data
>>> 1996 @Bill Clinton more data
>>> 2000 G. W. Bush more data
>>> 2004 G. W. Bush more data
>>> 2008 @Barack Obama more data
>>>
>>> What I want the output to look like is where the names actually line
>>> up in columns so that a space occurs in front of those names without
>>> the @.
>>>
>>> Is there anyway that this can be done? Thanks.
>>
>> This is how I understand your requirement on the data you provided...
>>
>> awk '!/@/ { $2 = " "$2 } 1'
>
> That'd also change "Obama more" to "Obama more" which may not be
> desirable.

To me that looked more like a typo in the OP's ad-hoc data.

Janis

>
> Ed.
From: Ed Morton on
On 6/20/2010 5:49 AM, Ed Morton wrote:
> On 6/20/2010 2:56 AM, Janis Papanagnou wrote:
>> Lao Ming wrote:
>>> I have a collection of files of all ascii data in which certain lines
>>> contain an @ char. In the lines that don't have the @ char, I want to
>>> substitute a space. However, since the @ is not at the beginning or
>>> end of the line, I am having difficulty determining how to accomplish
>>> this.
>>>
>>> The data below is not the real data but it is a simple accurate
>>> example of what I want to do.
>>>
>>> 1988 G. H. W. Bush more data
>>> 1992 @Bill Clinton more data
>>> 1996 @Bill Clinton more data
>>> 2000 G. W. Bush more data
>>> 2004 G. W. Bush more data
>>> 2008 @Barack Obama more data
>>>
>>> What I want the output to look like is where the names actually line
>>> up in columns so that a space occurs in front of those names without
>>> the @.
>>>
>>> Is there anyway that this can be done? Thanks.
>>
>> This is how I understand your requirement on the data you provided...
>>
>> awk '!/@/ { $2 = " "$2 } 1'
>
> That'd also change "Obama more" to "Obama more" which may not be desirable.

....not really given that line has an "@" but you get the point that there do
appear to be chains of multiple contiguous white spaces in the input....

Ed.
From: Janis Papanagnou on
Ed Morton wrote:
> On 6/20/2010 5:49 AM, Ed Morton wrote:
>> On 6/20/2010 2:56 AM, Janis Papanagnou wrote:
>>> Lao Ming wrote:
>>>> I have a collection of files of all ascii data in which certain lines
>>>> contain an @ char. In the lines that don't have the @ char, I want to
>>>> substitute a space. However, since the @ is not at the beginning or
>>>> end of the line, I am having difficulty determining how to accomplish
>>>> this.
>>>>
>>>> The data below is not the real data but it is a simple accurate
>>>> example of what I want to do.
>>>>
>>>> 1988 G. H. W. Bush more data
>>>> 1992 @Bill Clinton more data
>>>> 1996 @Bill Clinton more data
>>>> 2000 G. W. Bush more data
>>>> 2004 G. W. Bush more data
>>>> 2008 @Barack Obama more data
>>>>
>>>> What I want the output to look like is where the names actually line
>>>> up in columns so that a space occurs in front of those names without
>>>> the @.
>>>>
>>>> Is there anyway that this can be done? Thanks.
>>>
>>> This is how I understand your requirement on the data you provided...
>>>
>>> awk '!/@/ { $2 = " "$2 } 1'
>>
>> That'd also change "Obama more" to "Obama more" which may not be
>> desirable.
>
> ...not really given that line has an "@" but you get the point that
> there do appear to be chains of multiple contiguous white spaces in the
> input....

I was aware of that when posting the suggestion. But you certainly agree
that given the OP's "specification" we can guess all day long, and build
bulletproof applications by guessing and assuming yet more details the
OP might have missed to tell us. That's why I've initially pointed out;
>>>
>>> If that's not what you want, please provide an appropriate sample and
>>> also a sample of how the output should look like.

Janis

>
> Ed.
From: Dominic Fandrey on
On 20/06/2010 12:48, Ed Morton wrote:
> On 6/20/2010 12:20 AM, Lao Ming wrote:
>> I have a collection of files of all ascii data in which certain lines
>> contain an @ char. In the lines that don't have the @ char, I want to
>> substitute a space. However, since the @ is not at the beginning or
>> end of the line, I am having difficulty determining how to accomplish
>> this.
>>
>> The data below is not the real data but it is a simple accurate
>> example of what I want to do.
>>
>> 1988 G. H. W. Bush more data
>> 1992 @Bill Clinton more data
>> 1996 @Bill Clinton more data
>> 2000 G. W. Bush more data
>> 2004 G. W. Bush more data
>> 2008 @Barack Obama more data
>>
>> What I want the output to look like is where the names actually line
>> up in columns so that a space occurs in front of those names without
>> the @.
>>
>> Is there anyway that this can be done? Thanks.
>
> Sounds like this might be what you want:
>
> awk '!/@/{sub(/ /," ")}1' file

Note that "more data" may not contain the @ character for this to work.

--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
From: Ed Morton on
On 6/20/2010 5:57 AM, Janis Papanagnou wrote:
> Ed Morton wrote:
>> On 6/20/2010 5:49 AM, Ed Morton wrote:
>>> On 6/20/2010 2:56 AM, Janis Papanagnou wrote:
>>>> Lao Ming wrote:
>>>>> I have a collection of files of all ascii data in which certain lines
>>>>> contain an @ char. In the lines that don't have the @ char, I want to
>>>>> substitute a space. However, since the @ is not at the beginning or
>>>>> end of the line, I am having difficulty determining how to accomplish
>>>>> this.
>>>>>
>>>>> The data below is not the real data but it is a simple accurate
>>>>> example of what I want to do.
>>>>>
>>>>> 1988 G. H. W. Bush more data
>>>>> 1992 @Bill Clinton more data
>>>>> 1996 @Bill Clinton more data
>>>>> 2000 G. W. Bush more data
>>>>> 2004 G. W. Bush more data
>>>>> 2008 @Barack Obama more data
>>>>>
>>>>> What I want the output to look like is where the names actually line
>>>>> up in columns so that a space occurs in front of those names without
>>>>> the @.
>>>>>
>>>>> Is there anyway that this can be done? Thanks.
>>>>
>>>> This is how I understand your requirement on the data you provided...
>>>>
>>>> awk '!/@/ { $2 = " "$2 } 1'
>>>
>>> That'd also change "Obama more" to "Obama more" which may not be
>>> desirable.
>>
>> ...not really given that line has an "@" but you get the point that
>> there do appear to be chains of multiple contiguous white spaces in the
>> input....
>
> I was aware of that when posting the suggestion. But you certainly agree
> that given the OP's "specification" we can guess all day long, and build
> bulletproof applications by guessing and assuming yet more details the
> OP might have missed to tell us.

Right, just thought it was worth pointing out since there was that
multiple-space example.

Ed.

That's why I've initially pointed out;
>>>>
>>>> If that's not what you want, please provide an appropriate sample and
>>>> also a sample of how the output should look like.
>
> Janis
>
>>
>> Ed.