From: Lao Ming on
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.
From: Janis Papanagnou on
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'

If that's not what you want, please provide an appropriate sample and
also a sample of how the output should look like.

Janis
From: Dominic Fandrey on
On 20/06/2010 07:20, Lao Ming wrote:
> 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.

sed -E 's/^([[:digit:]]{4} )([^@])/\1 \2/' FILE

should do the trick.

Regards

--
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 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

Posting the expected output for your sample input would've helped.

Ed.
From: Ed Morton on
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.

Ed.