Re: sed replacing space/(s) with a tab in one place only



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



Relevant Pages

  • Bash-4.0 available for FTP
    ... Unlike previous bash distributions, this tar file includes the formatted ... The shell has been changed to be more ... rigorous about parsing commands inside command substitutions, ... Changes have been made to the Readline library being released at ...
    (gnu.announce)
  • Why newbies dont RTFM...
    ... Even though I've used Linux before, I've never had to do any ... BASH BUILTIN COMMANDS ... last command exited within ... unless the shell is not exeâ ...
    (comp.os.linux.misc)
  • Re: Great SWT Program
    ... None of the nasty things that you have said or implied about me are at ... treat the file as input (manually invoking the command interpreter ... script, copy the line into that within the editor, exit, and invoke ... the shell script. ...
    (comp.lang.java.programmer)
  • Re: Shell function - accessing an Access secure db (.MDW file)
    ... > Hi - Does anyone know the correct syntax for the shell function. ... You can use the Shell command. ... To execute internal DOS command (Dir, Copy, ... Private Declare Function OpenProcess _ ...
    (microsoft.public.vb.general.discussion)
  • Re: ksh silently ignores function if mistakenly not autoloaded
    ... Here's the order of execution. ... This really takes place prior to command ... Shell scripts, with all their power, have one major drawback - they ... In the Korn Shell, there are two separate syntaxes for defining ...
    (comp.unix.shell)