Replace Double space with ||


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace Double space with ||
# 1  
Old 02-15-2010
Replace Double space with ||

Hi Guys,

I am trying to replace Double space with ||. But even the single space is getting replace with |.

Can you please point out my mistake.

I am trying to do it with translate command

Code:
tr "  " "||"

Regards,
Magesh
# 2  
Old 02-15-2010
Try with sed...

Code:
sed 's/  /||/'g' infile


Last edited by malcomex999; 02-15-2010 at 09:30 AM..
# 3  
Old 02-15-2010
The reason is this: tr translates any character that matches one of the characters in the first string to the character at the same position in the second string. For example, to translate a string to all uppercase, use
Code:
echo "MiXeD cAsE" | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

or shorter
Code:
echo "MiXeD cAsE" | tr '[a-z]' '[A-Z]'

It's not meant to translate sequences of multiple characters. That's what sed and company are for.
# 4  
Old 02-15-2010
thanks malcomex, that worked like charm.. still i am wondering what went wrong in my tr command.. can you or anybody throw some light on it?

thanks for the comment
# 5  
Old 02-15-2010
Pludi already explained it up.

just scroll up a little bit!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace Double quotes within double quotes in a column with space while loading a CSV file

Hi All, I'm unable to load the data using sql loader where there are double quotes within the double quotes As these are optionally enclosed by double quotes. Sample Data : "221100",138.00,"D","0019/1477","44012075","49938","49938/15043000","Television - 22" Refurbished - Airwave","Supply... (6 Replies)
Discussion started by: mlavanya
6 Replies

2. Shell Programming and Scripting

Replace double quotes with a single quote within a double quoted string

Hi Froum. I have tried in vain to find a solution for this problem - I'm trying to replace any double quotes within a quoted string with a single quote, leaving everything else as is. I have the following data: Before: ... (32 Replies)
Discussion started by: pchang
32 Replies

3. Shell Programming and Scripting

Replace newline character between a double quotes to a space

Hi Guys, I have a file with content as below aj.txt "Iam allfine" abcdef abcd "all is not well" What I'm trying to say is my data has some new line characters in between quoted text. I must get ride of the newline character that comes in between the quoted text. output must be:... (8 Replies)
Discussion started by: ajahuja
8 Replies

4. UNIX for Dummies Questions & Answers

replace %20 with space

Hi, I need torename filenames with %20 to space in a batch wise.Can anyone help me please. Need it badly Eg. English%20Brochure%20002-1 to be replace to English Brochure 002-1 Thanks a lot Please use and tags when posting code, data or logs etc. to preserve formatting... (8 Replies)
Discussion started by: umapearl
8 Replies

5. Shell Programming and Scripting

Replace double double quotes using AWK/SED

Hi, I have data as "01/22/97-"aaaaaaaaaaaaaaaaa""aaa""aabbbbbbbbcccccc""zbcd""dddddddddeeeeeeeeefffffff" I want to remove only the Consequitive double quotes and not the one which occurs single. My O/P must be ... (2 Replies)
Discussion started by: Bhuvaneswari
2 Replies

6. Programming

Replace one space with nothing

hi, d o g e v o l i want a perl command for the above string which should change to the below dog evol replace one space with nothing and two spaces with one space. Thanks, Amey (3 Replies)
Discussion started by: ameyrk
3 Replies

7. Shell Programming and Scripting

Replace long space to become one space?

Hi, i have the log attached. Actually i want the long space just become 1 space left like this : Rgds, (12 Replies)
Discussion started by: justbow
12 Replies

8. UNIX for Dummies Questions & Answers

Double space

Hi. this is my code: set common2 = "1 2 3 4" echo $common2 you can see that between 1 and 2 there is double space but the output is 1 2 3 4 and not 1 2 3 4 what is the problam??? (4 Replies)
Discussion started by: nirnir26
4 Replies

9. Shell Programming and Scripting

Replace space

Hai masters, If a file contains content of 2000 lines, from which i need to remove the first n characters or first n spaces from each line of the file. If suppose to remove n characters or first n spaces from a single line means, just use the command nx. But from the above scenario,... (9 Replies)
Discussion started by: ecearund
9 Replies

10. Shell Programming and Scripting

replace space by _

Hi I need to know how I change the spaces by _ in folders and filder founded by find ex. find . -name "* *" -exec echo {} \; ./test space ./test space/new file.txt ./test space/new file ./test space/untitled folder ./test space/untitled folder/new fileruben ./Backup/backup/Image... (6 Replies)
Discussion started by: ruben.rodrigues
6 Replies
Login or Register to Ask a Question