Re: sed replacing space/(s) with a tab in one place only
- From: Janis Papanagnou <janis_papanagnou@xxxxxxxxxxx>
- Date: Fri, 07 May 2010 23:11:24 +0200
Stu wrote:
On May 7, 3:50 pm, Janis Papanagnou <janis_papanag...@xxxxxxxxxxx>
wrote:
Stu wrote:
I have a data file that leads off with a number( after the last digitYou asked a similar question in comp.lang.awk just before. Would you
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.
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:- Show quoted text -
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 -
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
- References:
- sed replacing space/(s) with a tab in one place only
- From: Stu
- Re: sed replacing space/(s) with a tab in one place only
- From: Janis Papanagnou
- Re: sed replacing space/(s) with a tab in one place only
- From: Stu
- sed replacing space/(s) with a tab in one place only
- Prev by Date: Re: sed replacing space/(s) with a tab in one place only
- Next by Date: Re: extract field
- Previous by thread: Re: sed replacing space/(s) with a tab in one place only
- Next by thread: Re: [OT] User-Agent headr (Was: List -h by size)
- Index(es):
Relevant Pages
|