Insert a special character $ in place of extra spaces

Hi Experts,

I have called some.txt with the following content.

oracle            HYRDSRVIHUB01       pts/0                               TESTIHUB                07-JUN-10 CREATE                         TABLE 
             TESTIHUB                       PHONE                                         create table phone ( name varchar2(30), Nber number, type varchar2(20) ).

Now i want to remove extra spaces and replace with $ symbol in between them.

I have used tr -s ' ' < some.txt to remove extra spaces but unable to substitute any $ with extraspace.

My desired out put is :

oracle$HYRDSRVIHUB01$pts/0$TESTIHUB$07-JUN-10$CREATE$TABLE$TESTIHUB$PHONE$create table phone ( name varchar2(30), Nber number, type varchar2(20) ). 

Can you please me.

Regards
Naree

sed "s/  */$/g"

It doesn't append $ after the date:

naresh@HYRDSRVIHUB01:~/test> sed "s/    */$/g" some.txt
oracle$HYRDSRVIHUB01$pts/0$TESTIHUB$07-JUN-10 CREATE$TABLE$TESTIHUB$PHONE$create table phone ( name varchar2(30), Nber number, type varchar2(20) ).

Can please help me.

Regards
Naree.

You have 4 spaces here:

"s/    */$/g"

There should only be 2

"s/  */$/g"

And PLEASE use code tags.

Helo, in this place there is a spanish section. How I go in there. Thank

Still not working.

naresh@HYRDSRVIHUB01:~/test> cat testihub.log | grep 07-JUN-10 | sed "s/  */$/g"
oracle$HYRDSRVIHUB01$pts/0$TESTIHUB$07-JUN-10$CREATE$TABLE$TESTIHUB$SHOP$create$table$shop$($proname$varchar2(30),$price$number,$stock$number$)$

But in your example there does seem to be a $ after 07-JUN-10 , no?

Oherwise try:

sed "s/[[:space:]]\{1,\}/$/g" infile

or:

sed "s/[ \t]\{1,\}/$/g" infile

or

sed "s/[ \t][ \t]*/$/g" infile

Try

sed 's/   */$/g' file

with three whitespaces between slash and star.

sed 's/   */$/g;s/ CREATE/$CREATE/' file
oracle$HYRDSRVIHUB01$pts/0$TESTIHUB$07-JUN-10$CREATE$TABLE$TESTIHUB$PHONE$create table phone ( name varchar2(30), Nber number, type varchar2(20) ).

Yeah, right ^^ or

sed 's/   */$/g;s/10 /10$/' file

What about next year :cool:

naree,

How is the line inside the input file generated? May be we can design a better solution by going to the root of the problem. If the line is generated by some SQL query, you may be able to get a simpler fix by modifying the query a little bit.

The TRIM() function can get rid of extra spaces in Oracle SQL. And you can insert a '$' between columns very easily by doing something like:


  SELECT TRIM(col1) || '$' TRIM(col2)
  FROM ...

Ok, this is just a hunch but I think the OP wants multiple spaces replaced by "$" only in the portion to the left of the "create table" statement.

The desired output in the OP's first post is like so -

And in a later post -

by "still not working", the OP probably means "still not working because the spaces in the "create table" statement as well have all been replaced by "$" characters.

Maybe the file is to converted to a "$"-delimited text file with the "create table" statement as the last token.

And here's Perl to the rescue -

$
$
$ cat -n some.txt
     1  oracle            HYRDSRVIHUB01       pts/0                               TESTIHUB                07-JUN-10 CREATE                         TABLE             TESTIHUB                       PHONE                                         create table phone ( name varchar2(30), Nber number, type
varchar2(20) ).
$
$
$ perl -lne 'if (/^(.*?)(create table.*)$/){$x=$1; $y=$2; $x=~s/\s+/\$/g; print "$x$y"}' some.txt
oracle$HYRDSRVIHUB01$pts/0$TESTIHUB$07-JUN-10$CREATE$TABLE$TESTIHUB$PHONE$create table phone ( name varchar2(30), Nber number, type varchar2(20) ).
$
$

I've assumed that that's just one line.

tyler_durden