1834789 Members
2579 Online
110070 Solutions
New Discussion

Re: sed problem

 
SOLVED
Go to solution

sed problem

I have a problem where I would like to replace / with tabs. I am using

sed s/[/]//g

but hitting the tab key does not work. Any ideas why not? Or how else I might do this?
Thanks!
19 REPLIES 19
Robin Wakefield
Honored Contributor

Re: sed problem

Hi Michael,

I think you might just be missing quotes. This works for me:

sed 's+/+ +g' filename

where I just pressed that tab key between the 2nd pair of "+" chars.

rgds, Robin
Christian Gebhardt
Honored Contributor

Re: sed problem

Hi

simply press the TAB-Button instead of

Chris

Re: sed problem

Robin & Christian,

I am hitting the actual tab key and it does not work, either in my example or in Robin's.
Hai Nguyen_1
Honored Contributor

Re: sed problem

Michael,

Hitting the tab key should work. Try this below:

# echo "field1/field2" | sed 's:/::'

Hai
Richard Hood
Advisor

Re: sed problem

You can do the substitution with vi.

vi
~
~
~
~
~
:g/\///s///gp


This will globally change the "/" to a

You will need to :x! to save and exit vi

If it ain't broke - Don't fix it
Robin Wakefield
Honored Contributor

Re: sed problem

Hi Michael,

What does this show:

echo a/b | sed 's+/+ +g' | od -c

I see:

# echo a/b | sed 's+/+ +g' | od -c
0000000 a \t b \n
0000004

rgds, Robin
Richard Hood
Advisor

Re: sed problem

global line should read

:g/\//s///gp


I had one too many "/"'s sorry
If it ain't broke - Don't fix it
S.K. Chan
Honored Contributor

Re: sed problem

This works for me (ie using the tab key).
# cat myfile | sed 's/\///g'
Richard Hood
Advisor

Re: sed problem

you can also try to put the ctrl-v before the ,tab - on the sed line -- either way works for me. as well..
If it ain't broke - Don't fix it
James R. Ferguson
Acclaimed Contributor
Solution

Re: sed problem

Hi:

Robin's syntax works fine. Don't copy-and-paste it. Try replicating the TAB character both with the tab key and by pressing "control", "v" and then "I". This can be done at commandline and should act identically to pressing the tab key. In fact, you should see your cursor move.

Regards!

...JRF...
John Meissner
Esteemed Contributor

Re: sed problem

sed 's /\//g'
All paths lead to destiny
John Meissner
Esteemed Contributor

Re: sed problem

sed 's /\///g'
All paths lead to destiny
John Meissner
Esteemed Contributor

Re: sed problem

sorry for the almost the same double post.... i caught my type-o just as I hit send on the first one.
All paths lead to destiny

Re: sed problem

Robin, I get the following:

[immpact:immpacts]:~/bin
bash-2.05$ echo a/b | sed 's+/+ +g' | od -c

0000000 a b \n
0000004

[immpact:immpacts]:~/bin
bash-2.05$

James, when I type ctrl-v then I, I get an I on the line.

Everyone else,
Anything requiring the tab key does not seem to work. At the console, the tab key doesn't do anything. Might this be a shell issue? The account I'm working under uses bash.

Re: sed problem

Duh! It's a shell issue of some sort. As the user under bash, no tab key. As root under sh, all of your examples work!

Anyone have a clue what could be different in the enviroments to cause tab not to work? If it matters, this is a k class running 10.20.
John Poff
Honored Contributor

Re: sed problem

Hi,

I got this example to work in my bash shell [on my Linux box]:

sed 's#/#\t#g'

The slashes were a little confusing in the substitution syntax, so I replaced them with the '#' sign. For the tab character, I used the \t expression.

JP
John Poff
Honored Contributor

Re: sed problem

Oops. Scratch my previous post. It doesn't work. But I did get it to work with the control-v method.

JP
James R. Ferguson
Acclaimed Contributor

Re: sed problem

Hi (again):

John P: The '\t' to represent a tab character doesn't work in all 'sed' versions. It does in gnu's 'sed' by not the HP version, for instance.

When using the "control, v, I" key sequence to generate a tab, press "ctrl", then press "v" and release that key, and finally while holding down the "ctrl" key, press "I". You should not see a visible "I" unless is appears as "^I". In my case, blank space appears and the cursor moves.

Regards!

...JRF...
John Meissner
Esteemed Contributor

Re: sed problem

I did have this problem (with shells) between by linux box (bash) and my Unix server (ksh). I was developting a script on my linux box to eventually run on my unix server.... i couldn't get it to work in the bash prompt but as soon as i tried in on my ksh shell everything worked.
All paths lead to destiny