Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sed TAB problems 1

Status
Not open for further replies.

LGJ

Programmer
Mar 7, 2003
50
GB
Hi,

I can't seem to delete TABS from say every line in a file?

I have tried sed 's/[ \t]*$//' filename > newfile

This should deleted all trailing TABS at the end of all the lines in filename?

How do I get this to work , I cant use the TAB button in place of the \t from the command line?

Thanks
 
Can do it If I put the sed command in a file and manually press the TAB button BUT still curious if it can be done on the command line??

Thanks
 
From the command line, you should be able to use control-v followed by a tab to generate a literal tab. This should not be necessary in Bourne shell or ksh, but is necessary if you are using bash, since tab is the command completion key. If you substitute this for your current
Code:
[\t]
, it will only remove tabs that are at the end of the line.
 
Yes I am using bash. I was able to input a TAB by doing this but it didn't work when I ran it?? (the tabs where still in the line)
 
to substitute ALL tabs with the string &quot;<tab>&quot;:
sed -e &quot;s/`echo &quot;\t&quot;`/<tab>/g&quot; tab.txt

to do the trailing tabs ONLY [same idea]:
sed -e &quot;s/`echo '\t'$`/<tab>/g&quot; tab.txt vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
use [tab]

where tab=the tab key

to change all tabs & multiple spaces you would use

s/[spacetab][tabspace]/ /g

--
| Mike Nixon
| Unix Admin
| ----------------------------
 
Still not working on command line.

Remember this is using Bash try it out and redirect to a new file and see the tabs still present??
 
No keyboard tricks, this will just delete all tab characters (octal 011)
[tt]
cat file1 |tr -d &quot;\011&quot; > file2
[/tt]
 
ok, bash has the builtin 'echo'.
try this:

sed -e &quot;s/$(echo -e '\t')/<tab>/g&quot; tab.txt vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Too delete the tab at the end of very line this works:

sed &quot;s/$(echo -e '\t')\$//&quot; tab.txt

Nice trick there vlad.

-jim
 
i am not on an unix box, this is NOT tested, but
sed -e 's/atab//' in >out
shoud work
NOTA: atab is a tab fron kb not a '\t'
sure you can also use 'tr'
 
#!/bin/sh
# This will preserve tabs except trailing, assuming no pipes in file1.
# Also works at command line.
cat file1 | tr &quot;\011&quot; &quot;|&quot; | sed 's/|*|$//' | tr &quot;|&quot; &quot;\011&quot; > file2
Visit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top