how to replace a character with blank in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to replace a character with blank in a file
# 1  
Old 02-02-2010
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

Code:
4:ALTER SYSTEM DISCONNECT SESSION '193,191' IMMEDIATE;
6:ALTER SYSTEM DISCONNECT SESSION '205,7274' IMMEDIATE;
5:ALTER SYSTEM DISCONNECT SESSION '206,34158' IMMEDIATE;
8:ALTER SYSTEM DISCONNECT SESSION '211,154' IMMEDIATE;

i want remove first two characters in every line (i mean 4: like that), i have tried through sed like below

Code:
sed s/[1-4]://g

but not working

Thanks,
Sri.

Last edited by Franklin52; 02-02-2010 at 08:23 AM.. Reason: Please use code tags!
# 2  
Old 02-02-2010
Code:
sed 's/..//' file

# 3  
Old 02-02-2010
Below code is not working (it not modifying with blank space).
# 4  
Old 02-02-2010
Sorry, misread that:

Code:
sed 's/../ /' file

The output goes to stdout, to change the file you can use the -i option if your sed version supports that otherwise you can use a temporary file:

Code:
sed 's/../ /' file > tempfile && mv tempfile file

# 5  
Old 02-02-2010
try this

Code:
 
sed 's/^[0-9]:/  /g'  infile

Login or Register to Ask a Question

Previous Thread | Next Thread

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. Shell Programming and Scripting

[bash] - Replace blank and string in csv file

Hi all, i have a .csv file with only two columns, like: Login;Status Luca;S Marco; Stefano; Elettra;S Laura; ... I need to replace the blank space on Status column whit Enabled end, on the same column, S whit Disabled, like: Login;Status Luca;Disabled Marco;Enabled Stefano;Enabled... (10 Replies)
Discussion started by: kamose
10 Replies

3. Shell Programming and Scripting

How to replace blank tab with zero in a file?

hi, i need to replace a blank tab output in a file to zero. input file: 2015/08/04 00:00:00 171 730579 27088 <blank> 3823 30273 1621778 ... (6 Replies)
Discussion started by: amyt1234
6 Replies

4. UNIX for Dummies Questions & Answers

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... (13 Replies)
Discussion started by: newbie83
13 Replies

5. Shell Programming and Scripting

replace blank field in file 2 with content of file 1

Something like vlookup in excel, column 2 in file 2 is blank and should be replaced by column 2 in file 1 based on comparing column 1 in both files. file1 Code: 1234~abc~b~c~d~e~f~g~h~09/10/09 5678~def~b~c~d~e~f~g~h~12/06/10 8910~hij~b~c~d~e~f~g~h~03/28/13... (1 Reply)
Discussion started by: sigh2010
1 Replies

6. Shell Programming and Scripting

Replace last character in file

Greetings UNIX folks, I am running a tcsh script and trying to replace the last character of a file with the number 0. I know that the last character of the file will always be 1, but I only want to replace the last character. Example: 78062 26.55 78.77 1 MYGF1 24.89 15.78 1 ... (2 Replies)
Discussion started by: TheSMan5
2 Replies

7. Shell Programming and Scripting

Replace blank spaces with semicolon - text file

Hi all, Been trying to find a solution to this, I'm sure its a sed 1 liner, but I don't know sed well enough to work it out... I have a text file in the following format: 431 666 1332 2665 0.24395 432 670 ... (3 Replies)
Discussion started by: mpcengineering
3 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. Shell Programming and Scripting

How to replace a character in the file?

Hi All, I have file contains the following information. chem00s4.mis.amat.com ] Critical 3/21 chem00s4.mis.amat.com ] Normal 3/22 chem00s4.mis.amat.com ] Normal 3/23 chem00s4.mis.amat.com ] Normal 3/24 chem00s4.mis.amat.com ] Critical 3/25... (2 Replies)
Discussion started by: ntgobinath
2 Replies

10. 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
Login or Register to Ask a Question