Replacing / with a space using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing / with a space using awk
# 1  
Old 09-19-2010
Replacing / with a space using awk

I have a string and want to replace the / with a space.

For example having "SP/FS/RP" I want to get "SP FS RP"

However I am having problems using gsub

Code:
set phases = `echo $Aphases | awk '{gsub(///," ")}; {print}'`

# 2  
Old 09-19-2010
You need to escape the slant:

Code:
gsub( /\//, " ", $0 );

# 3  
Old 09-19-2010
Code:
tr / ' '

# 4  
Old 09-19-2010
Code:
$
$
$ echo "SP/FS/RP" | sed 's/\// /g'
SP FS RP
$
$
$ echo "SP/FS/RP" | perl -plne 's/\// /g'
SP FS RP
$
$

tyler_durden
# 5  
Old 09-19-2010
Code:
$ echo "SP/FS/RP"|ruby -e 'puts gets.split("/").join(" ")'
SP FS RP

# 6  
Old 09-20-2010
Another one with awk:
Code:
awk -F/ '$1=$1'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing space with hyphen in a pattern.

I have a huge text file, about 52 GB. In the file, there are patterns like these: ] ] ] ]One can see that there is text within patterns such as and ], and I am only interested in ]. There is text before and after all these patterns too, for example, ''Anarchism''' is a ] that advocates ]... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

2. Shell Programming and Scripting

Replacing trailing space with single quote

Platform : RHEL 5.8 I want to end each line of this file with a single quote. $ cat hello.txt blueskies minnie mickey gravity snoopyAt VI editor's command mode, I have used the following command to replace the last character with a single quote. ~ ~ ~ :%s/$/'/gNow, the lines in the... (10 Replies)
Discussion started by: John K
10 Replies

3. Shell Programming and Scripting

Replacing a string with a space

I'm trying to replace a string "99999999'" with the blank where ever is there in the file. Could you please help in unix scripting. Thank You. (6 Replies)
Discussion started by: vsairam
6 Replies

4. Shell Programming and Scripting

Suppressing space replacing by comma

hi i want to replace spaces by comma my file is ADD 16428 170 160 3 WNPG 204 941 No 204802 ADD 16428 170 160 3 WNPG 204 941 No 204803 ADD 16428 170 160 3 WNPG 204 941 No 204804 ADD... (9 Replies)
Discussion started by: raghavendra.cse
9 Replies

5. UNIX for Advanced & Expert Users

sed help on replacing space before and after *

I would like to replace the value of * (which might have one or more whitespace(s) before and after *) using sed command in aix. Eg: Var='Hi I am there * Desired output: Hi I am there* (1 Reply)
Discussion started by: techmoris
1 Replies

6. Shell Programming and Scripting

replacing all space seperates with tabs

hi, I have a file that is space separated at all columns. Basically what I want to do is replace all the space separations with column separations. Thanks kylle (1 Reply)
Discussion started by: kylle345
1 Replies

7. UNIX for Dummies Questions & Answers

Replacing underscore with white space after comma.

Hi all, I'm hoping you can help.. I've used this forum a couple of times and I am back again now i've moved onto something more complex (for me!) I have some data which looks like: "AL1_1,AL1_1," "AL1_1.AL1_1A.AL1_1AE,AL1_1AE," "AL1_1.AL1_1A.AL1_1AG,AL1_1AG," "AL1_1.AL1_1A.AL1_1AJ,AL1_1AJ,"... (10 Replies)
Discussion started by: gman
10 Replies

8. UNIX for Dummies Questions & Answers

replacing space with pipe(delimiter)

Hello All, I have a file with thousands of records: eg: |000222|123456987|||||||AARONSON| JOHN P|||PRIMARY |P |000111|567894521|||||||ATHENS| WILLIAM k|||AAAA|L Expected: |000222|123456987|||||||AARONSON| JOHN |P|||PRIMARY |P |000111|567894521|||||||ATHENS| WILLIAM |k|||AAAA|L I... (6 Replies)
Discussion started by: OSD
6 Replies

9. UNIX for Dummies Questions & Answers

Replacing URL in a file with space

Hi, I have a file with a URL text written in it within double quotes e.g. "http://abcd.xyz.com/mno/somefile.dtd" I want the above text to get replaced by a single space character. I tried cat File1.txt | sed -e 's/("http)*(dtd")/ /g' > File2.txt But it didnt work out. Can someone... (5 Replies)
Discussion started by: dsrookie
5 Replies

10. Shell Programming and Scripting

replacing single space in argument

I want to write a script which will check the arguments and if there is a single space(if 2 more more space in a row , then do not touch), replace it with _ and then gather the argument so, program will be ran ./programname hi hello hi usa now hello hello so, inside of program,... (7 Replies)
Discussion started by: convenientstore
7 Replies
Login or Register to Ask a Question