removing tabs

Hi Everyone,

Im trying to write a shell script that removes a "newline character followed by a tab" throughout a file. basically it should get rid of it. Here's an example

File Before

The cat sat on the
mat

File After
The cat sat on the mat

This message writing screen has problems showing tabs but basically there is a tab character before the word mat. THe shell script should loop through the entire file and find and replace all occurences of new line follwed by tab with nothing.
Does anyone know how to write a shell script to do this?

thanks

sed -e :a -e '$!N;s/\n\t/ /;ta' -e 'P;D' filename

Hi tanku,

Thanks for you efforts but this didnt seem to work..is there any syntax errors with the command you have mentioned?

thanks

sed 's/[     ]+/ /g' file > newfile

[ ] literally contains a TAB character. You may need to type "Ctrl+V" then "TAB" to get the character.
/ / contains one space.

there is no syntax errors. it works fine on my gnu sed.


$ cat filename
The cat sat on the
        mat

$ sed -e :a -e '$!N;s/\n\t/ /;ta' -e 'P;D' filename
The cat sat on the mat

Sorry, I left a bit out of my earlier post.

sed "N;s/\n[    ]/ /g' filename

Hi Tanku..

Can u explain the usage

dont know the swiches -e:a -e
then ta
P;D

please help

thanks in advance
esham

i stole it from handy one-liners for sed. the problem was similar to the example of a line that begins with an equal sign (sed -e :a -e '$!N;s/\n=/ /;ta' -e 'P;D')

-e cmd
Next argument is an editing command. Useful if multiple scripts or commands are specified.

:label
Label branched to by t or b.
b
Branch to label or to end of script.
t
Same as b, but branch only after substitution.

P
Print first part (up to embedded newline) of multiline pattern space created by N command. Same as p if N has not been applied to a line.

D
Delete the first part (up to embedded newline) of multi-line pattern space created by N command and resume editing with first command in script. If this command empties the pattern space, a new line of input is read, as if the d command had been executed.

of course you can also read the friendly manual