Replace character by blank

Thread Tools Search this Thread
# 8  
Please be more specific on the input file structure. Are the dots to be removed always embedded in spaces (obviously not at EOL!)? Are there integers with no dots? Are there integers surrounded by dots? Could there be single dots between integers? Are the numbers to stay intact always in the same place (column/position)? And don't surprise us again with "expanded data" once a proposal has been posted!
# 9  
awk '{for (i=1;i<=2;i++) gsub( /(^|[^0-9])\.([^0-9]|$)/ , "\1 \2")} 1'

Last edited by MadeInGermany; 06-26-2013 at 05:23 PM.. Reason: added loop to handle a row of dots
This User Gave Thanks to MadeInGermany For This Post:
# 10  
I`m sorry for all the confusion, I should have given a more specific description of the data set.

It is a tab delimited flat file, the dots represent missing data. So there will be a tab before and after the dot. I have attached a portion of a sample input from the large file.

The numbers are supposed to stay in the same place (row and column) after the dots have been removed. The decimal numbers remain intact , 12.34 remains 12.34 but simply a . or a missing data has to be represented by a white space or anything else to keep the structure of the table intact.
# 11  
Hi MadeInGermany,

I ran your code for the sample data set I attached, I`m getting an L like character in place of dot. Please pardon my ignorance, is there a way i could just have white space? Also I want to be able to keep the table structure intact, so that I can import it as a table into statistical software.

I have attached the output.

Thank you for helping out
# 12  
FIRST: your file is a DOS file, CR LF (0x0D 0x0A) terminated. To correctly work upon it, remove the CR chars from it (copiously covered in these fora).
Then try:
awk '{for (i=1; i<=NF; i++) if ($i==".") $i=" "}1' OFS="\t" sample_out.txt

@MadeInGermany: what you propose is a sedism; it does not work in (my m-) awk, but inserts ^A and ^B into the lines.
This User Gave Thanks to RudiC For This Post:
# 13  
Now I see that gsub() does not support \1 references.
Also I see one needs 3 cycles to replace a row of dots.
With perl this becomes:
perl -pe 'for ($i=1;$i<=3;$i++) { s/(^|\D)\.(\D|$)/$1 $2/g }'

There is certain a more elegant|efficient method with perl RE ...
This User Gave Thanks to MadeInGermany For This Post:
# 14  
works like a charm !! thanks Smilie

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

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