From: Stu on 7 May 2010 15:37 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
From: Ed Morton on 7 May 2010 15:49 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.
From: Janis Papanagnou on 7 May 2010 15:50 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
From: Stu on 7 May 2010 16:57 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. From the looks of this I think this will replace every space with a tab that not what I want. I want to only replace the space after the last digit of the number with a tab. Thanks anyway.
From: Stu on 7 May 2010 17:03
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 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. Thanks for the response |