Replace colon with blank space


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Replace colon with blank space
# 1  
Old 11-24-2011
Replace colon with blank space

Dear Gurus,

I have a unix file with multiple colons on each row, and I would like to replace each colon with a blank space using the awk command.

For example, I have the following data:

Data:
---------
Code:
A~000000000000518000~SLP:~99991231~20090701~00102.00~USD:~CS:~
A~000000000000772000~SLP:~99991231~20090701~00118.08~USD:~CS:~
A~000000000000775000~SLP:~99991231~20090701~00118.08~USD:~CS:~
A~000000000001720007~SLP:~99991231~20101101~00194.40~USD:~CS:~

---------

And result I would like to achieve is as follows:

Result:
---------
Code:
A~000000000000518000~SLP ~99991231~20090701~00102.00~USD ~CS ~
A~000000000000772000~SLP ~99991231~20090701~00118.08~USD ~CS ~
A~000000000000775000~SLP ~99991231~20090701~00118.08~USD ~CS ~
A~000000000001720007~SLP ~99991231~20101101~00194.40~USD ~CS ~

---------

Thanks in advance!

Chumsky


Moderator's Comments:
Mod Comment How to use code tags

Last edited by Franklin52; 11-24-2011 at 03:40 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 11-24-2011
Code:
$ nawk '{gsub(/:/," ")};1' infile

This User Gave Thanks to jayan_jay For This Post:
# 3  
Old 11-24-2011
jayan, you are a star Smilie Thank you
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace colon in HH:MI:SS to hypen?

I have a file that contains timestamp in some of the rows in the file and the field separator is colon and some of the rows have numerical values, timestamp and characters with colon as the field separator We are looking to change colon in HH:MI:SS for the timestamp to hyphen “-“ leaving the field... (1 Reply)
Discussion started by: cumeh1624
1 Replies

2. Shell Programming and Scripting

Not delete space blank

Hi everyone, i need to "grep" a file with a string with space blanks, like this: grep "XXXX XX" file.txt The problem, i need put the "XXXX XX" in a string variable. When the script executes the grep, do: gresp XXXX XX file.txt How can i solve this problem? The... (5 Replies)
Discussion started by: Xedrox
5 Replies

3. UNIX for Dummies Questions & Answers

blank space

hi everyone, i have a problem in unix script , i need to remove line that has blank , not blank line . example: mahm,,jdggkhsd,ghskj,,fshjkl can anyone help? (4 Replies)
Discussion started by: Reham.Donia
4 Replies

4. Shell Programming and Scripting

Replace carriage return with colon on specific column

Hi, I have to process four source text files with possibility to contain carriage return on the particular column. Thus, i need to replace the carriage return with 3 colons <:::> The particular column position in the source files is not fix but the name is fixed. That is, say for example,... (4 Replies)
Discussion started by: agathaeleanor
4 Replies

5. Shell Programming and Scripting

Cut last blank space

Hello, I am using this to get only directories : ls -l | grep '^d'and here is the result : drwx------ 13 so_nic sonic 13 Nov 4 13:03 GLARY drwx------ 3 so_nic sonic 3 May 6 2010 PSY2R drwx------ 15 so_nic sonic 15 Oct 14 08:47 PSYR1 But I only need to keep this... (7 Replies)
Discussion started by: Aswex
7 Replies

6. Shell Programming and Scripting

Replace comma with a blank space using SED

Hello everyone, I want to replace all "," (commas) with a blank space My command thus far is: cat test.text | sed -e s/\`//g | awk '{print$1" "$2" "$3}' I'm sure you guys know this, but the SED command that I am using is to get rid of the "`" (tics). which gives me: name ... (5 Replies)
Discussion started by: jayT
5 Replies

7. Shell Programming and Scripting

loop to replace txt and add command inside of colon (:)

in one of my script..I have some thing like john:christina : one:: and i want to make it like john:chritina:two:(date command):jackey: basically change 'one' to 'two' and run date :command and add other name: (30 Replies)
Discussion started by: Learnerabc
30 Replies

8. Shell Programming and Scripting

Replace a blank space with string "\\ "

Hi, I have a requirement to replace a every blank space with char "\\ ". Like string "God Love" to "God\\ Love" and "God Love" as "God\\ \\ Love". and only in the sed. We have already a script but it is replaceing all continuous blank space with one "\\ ". which is as DIR=`sudo echo... (7 Replies)
Discussion started by: Akshay4u
7 Replies

9. UNIX for Dummies Questions & Answers

Multiple field separators in awk? (First a space, then a colon)

How do I deal with extracting a portion of a record when multiple field separators are involved. Let's say I have: Mike Harrington;(555) 555-5555:250:100:175 Christian Dobbins;(555) 555-2358:155:90:201 Susan Dalsass;(555) 555-6279:250:60:50 Archie McNichol;(555) 555-1348:250:100:175 Jody... (3 Replies)
Discussion started by: doubleminus
3 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