Insert a special character $ in place of extra spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert a special character $ in place of extra spaces
# 8  
Old 06-07-2010
Try
Code:
sed 's/   */$/g' file

with three whitespaces between slash and star.
# 9  
Old 06-07-2010
Code:
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) ).

# 10  
Old 06-07-2010
Yeah, right ^^ or
Code:
sed 's/   */$/g;s/10 /10$/' file

# 11  
Old 06-07-2010
Quote:
Originally Posted by pseudocoder
Yeah, right ^^ or
Code:
sed 's/   */$/g;s/10 /10$/' file

What about next year Smilie
# 12  
Old 06-07-2010
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:

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

# 13  
Old 06-08-2010
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 -

Quote:
Originally Posted by naree
...
I have called some.txt with the following content.

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

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

...
And in a later post -

Quote:
Originally Posted by naree
Still not working.

Code:
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$)$

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 -

Code:
$
$
$ 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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep string causes extra spaces

Hello, I have an xml file and my aim is to grab each line in keywords file and search the string in another file. When keyword is found in xml file,I expect the script to go to previous line in the xml file and grab the string/value between two strings. It's almost working with an error. tab... (6 Replies)
Discussion started by: baris35
6 Replies

2. UNIX for Advanced & Expert Users

Replace certain character at specific place with related character

hello i have file with 100k records and each one has certain value that starts at 28th column and certain value that starts at 88th column e.g. 1st file <25>1234567 ..... <88> 8573785485 i have aditional file with values which are related to value that starts at 88th column of the... (1 Reply)
Discussion started by: dell1520
1 Replies

3. Shell Programming and Scripting

Delete Numbers, Spaces, Special Character from the begining of the line of a file

Hi All, I want to keep the name of the songs with their respective extensions only. Sample Code ======== 03 Choti choti gaiya choti choti gaval.mp3 03---Brazil Dhol.mp3 03 PAYALIYA .mp3 04 - Isq Risk .mp3 04%20-%20Oh%20My%20Love(wapking.in).mp3 08 - A2 - Aasan Nahin Yahan .mp3 AE... (3 Replies)
Discussion started by: Pramod_009
3 Replies

4. Shell Programming and Scripting

Remove blank space and insert special character

Hi Folks, I have a huge data of the below format abc #apple 1200 06/23 ghj #orange 1500 06/27 uyt #banana 2300 05/13 efg #vegetable 0700 04/16 After first 3 letters, i have 9 spaces and after fruit there are no specific fixed space, but it varies... (4 Replies)
Discussion started by: jayadanabalan
4 Replies

5. Shell Programming and Scripting

Insert underscore in place of column

Hi I tried to put underscore in place of column in a big file with lots of oclumns using the programm sed 's//_/g' Its showing error bash-3.2$ sed 's//_/g'saradrugbankgenedrugnewlist.txt >saradrugbankgenedrugnewlist3.txt sed: -e expression #1, char 11: unknown option to `s' if... (24 Replies)
Discussion started by: manigrover
24 Replies

6. Shell Programming and Scripting

Insert comma in place of column

Hi all, I have a file in which I have to insert commna between entries of 2 column and createa new file separated by commas not a columns if input is FHIT Adenosine Monotungstate Not Available CS Trifluoroacetonyl Coenzyme A Not Available Theo expected output is ... (5 Replies)
Discussion started by: manigrover
5 Replies

7. Shell Programming and Scripting

How to insert a character in line in Special condition?

Hi, I have a log file generated by a tool which has the following look : /tmp/releases/directory/datefilename1_release_date.zip /tmp/releases/directory/datefilename2_release_date.zip /tmp/releases/directory/datefilename3_release_date.zip... (8 Replies)
Discussion started by: bhaskar_m
8 Replies

8. Shell Programming and Scripting

remove extra spaces between fields

Hi, I have a source file as mentioned below: I want to remove all the extra spaces between the fields. a b--------|sa df-------|3232---|3 sf sa------|afs sdf-----|43-----|33 a b c------|adfsa dsf---|23-32|23 *Here '-' idicates spaces Now, I want output as below: a b|sa df|3232|3... (7 Replies)
Discussion started by: srilaxmi
7 Replies

9. Shell Programming and Scripting

How to insert a string in a file at specified place?

Hi all, I want to insert a string in a specified place of a very large file. I am giving an example of the task: I love football. Above is a sentence in a file and I want to insert a string "the" between love and football. It is not sure that where this particular line exists. It has to... (4 Replies)
Discussion started by: naw_deepak
4 Replies

10. Shell Programming and Scripting

adding lines at special place in crontab

Hi , i export the crontab in a file (i've no root right) and i would add lines from a file at a special place and rewrite the output in an another file. the special place is as this : 45 04 * * * /home/toto.sh > /dev/null 2>&1 # so i would search for toto.sh and insert the lines , the... (5 Replies)
Discussion started by: Nicol
5 Replies
Login or Register to Ask a Question