need help in replacing spaces in a file

hi all
this is the part i am facing a problem
eg data: filename : tr1

+ T 40

this is a sample record in that file ... the value of T can be anything, but will be a single character.

i need to cut from field two, and i am using this command
cut -d " " -f2 tr1 >tr3
and the o/p is
40

if i try to replace the spaces between + and T using sed

sed 's/\t/ /g' tr1>tr3

o/p :
+ T 40

it is not a tab.....

so i tried to replace it like this .....

tr -s " " "" tr1>tr3

o/p :

+ T 40 ...

it is not reading it as a space ....
more wierd is this ..
i tried to cut the file column wise ...

> cut -c 1 test1
+
> cut -c 2 test1

> cut -c 3 test1
T

i copied the record and pasted it in a notepad and i found that it is tab.

i cannot find out whether it is a space or a tab ....

can any one give me a solution ...

i am trying to do the following but not sure how to do ...
i want to replace everything that is there before tht "T" or "F" with a space... is it possible...?

First of all, i am sorry to say that i didnt understood ur problem , but whatever i understood

cat test
+ T 40

cat test | tr -d " " | sed -e 's/^./ /g;s/\( \)\(.\)/\1\2 /'
T 40

You can use something like the following

>cat test | od -An -t dC -w10

This will display the ASCII codes for your input file test.
That will tell you what is in your file. A space would be code 32, while a tab would be a 9. Carriage return and line feed are 13 and 10 respectively.

Take a look at this:

> echo "+ T 40" | od -An -t dC -w10
   43   32   84   32   52   48   10

This shows the two 32 characters and that they are spaces.

Aside: Both of your commands to remove spaces or tabs do not work. This is why you were misled.
Try:
To remove spaces:
tr -d " "
To remove tabs:
TAB=`echo "\0011"`
tr -d "${TAB}"

Notwithstanding "joeyg" good advice. To get a feel for whether white space is spaces or tabs you can substitute them both to make them visible.
TAB=`echo "\0011"`
cat filename|sed -e "s/${TAB}/TAB/g"|sed -e "s/ /SPACE/g"|pg
(Shell purists may cringe at this inefficient pipeline but it is only an example).

In your case the original problem is with using "cut" which requires a fixed delimiter.
If your use "awk" to get the second field it won't matter whether its a space or a tab.
cat filename|awk '{print $2}'

This code should be like this

cat test |sed -e 's/^.*+//g'|tr -d "\t"

It will take care any number of "tabs" or "spaces" present before the "+" sign. No matter its a "space or tabs". It will give the desired output. First give this a try at least :slight_smile:

guys please don't use cat command when you are going to use commands like awk,grep and sed because it can read the file
regards

thanks to everyone it worked :slight_smile:

awk '{print $1$2,$3}' filename