Prev: MAKE UPTO $5000 PER MONTH! $2000 IN FIRST 20 DAYS!
Next: (sh/bash) How to check for a string matching -*?
From: Janis Papanagnou on 20 Jun 2010 06:51 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 20 Jun 2010 06:51 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 20 Jun 2010 06:57 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 20 Jun 2010 07:38 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 20 Jun 2010 09:09 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.
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: MAKE UPTO $5000 PER MONTH! $2000 IN FIRST 20 DAYS! Next: (sh/bash) How to check for a string matching -*? |