Replace character by blank

Thread Tools Search this Thread
# 1  
Replace character by blank

Hi all,

I have 89 columns,1200 rows in a flat file, some of the values are just '.' (the character dot). I want to replace them by nothing (blank), but when I do so, it affects the decimal numbers too. so 12.34 becomes 1234.

How can I just replace values which are only '.' with 1 white space?


1.1 . . 2.2


1.1   2.2

# 2  
Can you post what you have tried so far...
# 3  
i would suggest to use a "cut" you can use a loop to move the cut N times across the columns check for a value, then loop through the rows in a loop. The use of a nested loops. I have an example of using the cut and nested loops
for scene in `ls $dirname` 
    if [ ! -d "${scene}" ]; then
        #this means its ...
        block.....Loop #function for single loop
        break  #exits the loops to give the counts
    curFrame=`ls $currPath | wc -l`

    for line in `ls $currPath | cut -d "." -f 2- |sort | uniq`
        count=`find $currPath -name "*.${line}"| wc -l `
        name1=$line #gives my my name per frame
        counttypes  #function "case statement"
    done #end for
    framecount=`expr ${framecount} + ${curFrame} `
done #end for

its may not be expert scripting but I am still learning it. Sorry had to edit some of the names and comments for posting...
This User Gave Thanks to weddy For This Post:
# 4  
I tried to sub the dots with white space

awk '{gsub( /./ , " ")'

# 5  
echo "1.1 . . 2.2" | sed 's/ \. \. /   /g'

1.1   2.2

These 2 Users Gave Thanks to in2nix4life For This Post:
# 6  
Originally Posted by in2nix4life
echo "1.1 . . 2.2" | sed 's/ \. \. /   /g'

1.1   2.2

this only works with the example values but doesn't work if i expand the data

 echo "1.1 . . 2.2 4.5 . ." | sed 's/ \. \. /   /g'
1.1   2.2 4.5 . .

# 7  
That was just an example to set you on your way. Since you didn't display an example of your file, this is just a guess, but it works when applied to a file:

cat file

1.1 . . 2.2  3.3 . . 4.4  5.5 . . 6.6  7.7 . . 8.8  9.9 . . 0.0  1.1 . . 2.2

sed 's/ \. \. /   /g' file

1.1   2.2  3.3   4.4  5.5   6.6  7.7   8.8  9.9   0.0  1.1   2.2

This User Gave Thanks to in2nix4life For This Post:

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Science: Mathematics
Difficulty: Easy
The 'Squaring the Circle' problem is solvable.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

In a file, replace blank line by the last line not blank above

Dear All, In a CSV file, say that a given column has been extracted. In that column, information is missing (i.e. blank lines appear). I would like to replace the blank lines by the last valid line (not blank) previously read. For example, consider the extract below: 123 234 543 111... (7 Replies)
Discussion started by: bagvian
7 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

Find character and Replace character for given position

Hi, i want find the character '-' in a file from position 284-298, if it occurs i need to replace it with 'O ' for the position in the file. How to do that using SED command. thanks in advance, Sara (9 Replies)
Discussion started by: Sara183
9 Replies

4. Shell Programming and Scripting

Replace multiple occurances of same character with a single character.

Hi all, Greetings, I have the following scenario, The contents of main file are like : Unix|||||forum|||||||||||||||is||||||the||best so||||||be|||||on||||||||||||||||||||||||||||||||||||||||||||it And i need the output in the following form: Unix=forum=is=the=best so=be=on=it ... (3 Replies)
Discussion started by: dipanchandra
3 Replies

5. Shell Programming and Scripting

In Sed how can I replace starting from the 7th character to the 15th character.

Hi All, Was wondering how I can do the following.... I have a String as follows "ACCTRL000005022RRWDKKEEDKDD...." This string can be in a file called tail.out or in a Variable called $VAR2 Now I have another variable called $VAR1="000004785" (9 bytes long), I need the content of... (5 Replies)
Discussion started by: mohullah
5 Replies

6. Shell Programming and Scripting

how to replace a character with blank in a file

hi, I have a doubt in replacing characters with blank. My requirement is that, i have one file and looks like below 4:ALTER SYSTEM DISCONNECT SESSION '193,191' IMMEDIATE; 6:ALTER SYSTEM DISCONNECT SESSION '205,7274' IMMEDIATE; 5:ALTER SYSTEM DISCONNECT SESSION '206,34158' IMMEDIATE;... (4 Replies)
Discussion started by: sridhusha
4 Replies

7. Shell Programming and Scripting

Replace two blank line with a single blank line

Hi Guys, I have a file in which each set of records are separated by two blank line. I want to replace it with a single blank line. Can you guys help me out? Regards, Magesh (9 Replies)
Discussion started by: mac4rfree
9 Replies

8. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies

9. AIX

How can i replace a character with blank space?

i want a command for my script!!! say file consists of character 123 125 127. i need a query to replace the number 2 with 0 so the output should be 103 105 107. i use unix-aix (8 Replies)
Discussion started by: rollthecoin
8 Replies

10. UNIX for Dummies Questions & Answers

check for the first character to be blank

I'm having a problem when the first line or first character of a file is blank. I need to get rid of both of them when they occur but don't want to delete the line. Does anyone have any suggestions? (7 Replies)
Discussion started by: anthreedhr
7 Replies

Featured Tech Videos