To replace '(' and ')' symbol using tr or sed


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers To replace '(' and ')' symbol using tr or sed
# 1  
Old 05-17-2012
To replace '(' and ')' symbol using tr or sed

I am trying to replace '(' and ')' symbol with nul text using tr command. But i am not able to get the expected output . Please help

Code:
# cat test.txt
155170816-(75767Mb)

#
Code:
 tr '(' '' < test.txt
155170816-(75767Mb)

Code:
# tr ')' '' < test.txt
155170816-(75767Mb)
#


I want the o/p as

Code:
155170816-75767Mb

Anyone please help. How can i do this using tr or sed.

Last edited by Scrutinizer; 05-17-2012 at 04:47 AM.. Reason: code tags
# 2  
Old 05-17-2012
Code:
 
$ echo "155170816-(75767Mb)" | sed 's,[()],,g'
155170816-75767Mb
 
sed 's,[()],,g' test.txt

# 3  
Old 05-17-2012
Code:
tr -d '()'

# 4  
Old 05-17-2012
Thanks itkamaraj,

Suppose if i want to get the o/p as 155170816-75767 meas how can i do in single command.

Code:
# cat test.txt
155170816-(75767Mb)

O/P must be

Code:
155170816-75767


Last edited by Scrutinizer; 05-17-2012 at 04:48 AM.. Reason: code tags
# 5  
Old 05-17-2012
Code:
$ echo "155170816-(75767Mb)" | sed 's,[Mb()],,g'
155170816-75767

# 6  
Old 05-17-2012
Code:
tr -d '()' < test.txt

# 7  
Old 05-17-2012
Code:
echo "155170816-(75767Mb)" | sed "s/[a-zA-Z()]//g"

 
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 the first and last character which is pipe symbol in all files within a folder?

with in my files i have the data like this, starting with a pipe and ending the line with a pipe. all i want is to replace the first and last pipe , remove those trying to use following sed command, but it is only showing on the screen the entire data of the file as if it removed, but when i... (4 Replies)
Discussion started by: cplusplus1
4 Replies

2. Shell Programming and Scripting

Remove/replace the very first character/symbol match

cat file.txt file 1123.x July 23:222 /cd/hh2/k39/ss2/f7d8d9d8e6r5t4s/dd2/e/s7a/s7a2afa5017d8b975-1.7-1395610245-b22e19bbc477b134 i wish to only extract out the 1.7 (anything within the first - -) i try to look for the sed command under match the first occurence of pattern but out of luck, my... (6 Replies)
Discussion started by: ctphua
6 Replies

3. Shell Programming and Scripting

Replace trailing whitespaces with pipe symbol using perl

I want to replace the whitespace with Pipe symbol to do a multiple pattern matching for the whole text "mysqld failed start" and same as for other text messages Below are the messages stored in a file seperate by whitespace mysqld failed start nfsd mount failed rpcbind failed to start for... (6 Replies)
Discussion started by: kar_333
6 Replies

4. Shell Programming and Scripting

remove caret (^) symbol from pattern using sed

Hi, I am trying to remove the caret symbol from a bash variable. This is the variable: var="GOTAN^TOK^B"and this is the code I am trying to use to remove the caret symbol: nocarrot=`echo $var | sed -e 's/^/_/g'`This is the output intended (but not acheived with the above function):... (3 Replies)
Discussion started by: goodbenito
3 Replies

5. Shell Programming and Scripting

How to replace quote symbol(") and dot(.) with some other values!!

Hi , I have below input file 1.order number is useful. 2.vendor_id is produced. 3.the vandor name is "malawar". I want output file like 1. order number is useful. 2. vendor_id is produced. 3. the vandor name is VmalawarV. in input file line number 1.order number there is no... (4 Replies)
Discussion started by: vinothsekark
4 Replies

6. Shell Programming and Scripting

replace multiple existence of : symbol with one

Infile Outfile (3 Replies)
Discussion started by: dvah
3 Replies

7. Shell Programming and Scripting

Spanish accent symbol removed by sed

Hello All in a text file I have to replace some numeric code by a string. This is an exemple of the file: 000000001 LDR L ^^^^^nam^^2200169Ia^45e0 000000001 008 L 100604s9999^^^^xx^^^^^^^^^^^^000^0^und^d 000000001 022 L $$a0365-6675 000000001 090 L $$aBMA 1934-1937. 000000001 245... (1 Reply)
Discussion started by: ldiaz2106
1 Replies

8. Solaris

/usr/lib/passwdutil.so.1: symbol __nsl_fgetspent_r: referenced symbol not found

deleteing post (0 Replies)
Discussion started by: dshakey
0 Replies

9. Linux

Replace cloud symbol with single quotes

Dear Experts My source file contains the symbol cloud (☁). How do i replace this ☁ symbol whose Unicode value is 2601 in linux file with single quotes ? Any help will be much appreciated. Many thanks (4 Replies)
Discussion started by: pklcnu
4 Replies

10. Shell Programming and Scripting

replace a symbol with new line

i have file in which i want to replace a char with new line please help me out (1 Reply)
Discussion started by: RahulJoshi
1 Replies
Login or Register to Ask a Question