From: Janis Papanagnou on
Stu wrote:
> On May 7, 3:49 pm, Ed Morton <mortons...(a)gmail.com> wrote:
>> On 5/7/2010 2:37 PM, Stu wrote:
>>
>>
>>
>>
>>
>>> I have a data file that leads off with a number( after the last digit
>>> in the number there are spaces than has some unique string, which
>>> include spaces.
>>> Ie 10<space><space>Jane<space> A.<apace> Doe
>>> 15<space><space>John<space>Q.<space>Public
>>> Is there a sed command I can run that can convert the space/(s) after
>>> the last digit of the
>>> number ONLY to a single tab
>>> Any sed examples would be greatly appreciated.
>>> My output should look like this:
>>> 10<tab>Jane<space> A.<apace> Doe
>>> 15<tab>John<space>Q.<space>Public
>>> Note that<space> is a literal space ' ' and<tab> is a literal tab.
>>> Thanks
>> sed 's/<space><space>*/<tab>/' file
>>
>> Ed.- Hide quoted text -
>>
>> - Show quoted text -
>
> Ed, your solution did not seem to work.

Have you tried it?

Sure it works with the data you posted here in c.u.s (it doesn't work
with your data posted in c.l.awk, though).

Of course you have to replace '<space>' by ' ' and '<tab>' by a TAB,
but you know that, don't you?

> From the looks of this I think

"From the looks" - ???

> this will replace every space with a tab that not what I want.

It replaces a sequence of at least one space *once* in a line. So if
your data example is accurate Ed's solution does exactly what you want.

> I want
> to only replace the space after the last digit of the number with a
> tab. Thanks anyway.
From: Janis Papanagnou on
Stu wrote:
> On May 7, 3:50 pm, Janis Papanagnou <janis_papanag...(a)hotmail.com>
> wrote:
>> Stu wrote:
>>> I have a data file that leads off with a number( after the last digit
>>> in the number there are spaces than has some unique string, which
>>> include spaces.
>>> Ie 10<space><space>Jane<space> A.<apace> Doe
>>> 15<space><space>John<space>Q.<space>Public
>>> Is there a sed command I can run that can convert the space/(s) after
>>> the last digit of the
>>> number ONLY to a single tab
>>> Any sed examples would be greatly appreciated.
>> You asked a similar question in comp.lang.awk just before. Would you
>> explain why you want specifically a sed solution here? You can of
>> course do it entirely in shell as well.
>>
>> while read -r num rest
>> do printf "%d\t%s\n" "$num" "$rest"
>> done < your_file
>>
>> Janis
>>
>>
>>
>>
>>
>>> My output should look like this:
>>> 10<tab>Jane<space> A.<apace> Doe
>>> 15<tab>John<space>Q.<space>Public
>>> Note that <space> is a literal space ' ' and <tab> is a literal tab.
>>> Thanks- Hide quoted text -
>> - Show quoted text -
>
> After I posted in the awk room I realized that this is basically a
> substitution and this would be better for sed, at least thats what I
> thought. As for doing it in the shell I would prefer just to pass my
> commands thru a pipe and deal with on file only to keep things simple
> instead of using two file names
>
> My command is basicially something liek this
> cat file | sort | uniq -c > file1

(Useles use of cat! Instead write this as

sort file | uniq -c > file1

And adding your additional commands to the shell code that I posted above

sort file | uniq -c |
while read -r num rest
do printf "%d\t%s\n" "$num" "$rest"
done > file1

>
> Doing it in the shell would require me to now read file1 and print to
> file2 and remove file thats why I thought the pipe
> would be better.

You have quite some misconceptions here.

Janis

>
> Thanks for the response