help to delete brackets [ ]


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help to delete brackets [ ]
# 1  
Old 01-18-2008
help to delete brackets [ ]

hi all,

i want to delete brackets in all the file and to keep the string or data between them ( example Q[xxxx] --> Qxxx) with sed command..



thanks
# 2  
Old 01-18-2008
You could try tr:
e.g.
Code:
 echo "Q[xxxx]" | tr -d "[]"

or
Code:
echo "Q[xxxx]" < file

# 3  
Old 01-18-2008
The brackets can be removed like any other character but have to be escaped because they have a special meaning to sed: "\[" will tell sed to treat the left bracket just as that character and with now special meaning at all. (Btw. the same is true for any other character with a special meaning, or "metacharacter" as is the correct denomination of these characters, too. "\*" will be an asterisk and not the wildcard, etc.).

Therefore your sed script is

Code:
sed 's/\[//g;s/\]//g' /path/to/file

It is possible to write that even shorter: you can use the bracket-construction itself, observe, that inside brackets metacharacters lose their meanings automatically so you don't even have to escape them:

Code:
sed 's/[[]]//g' /path/to/file

bakunin
# 4  
Old 01-18-2008
thanks but
i need a command for all the file cause a have many cases like Q[xxx]...
# 5  
Old 01-18-2008
Quote:
Originally Posted by kamel.seg
hi all,

i want to delete brackets in all the file and to keep the string or data between them ( example Q[xxxx] --> Qxxx) with sed command..



thanks
Code:
for i in $(ls /path/to/files*)
do
    sed 's/\[//;s/\]//' $i
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help - delete content inside square brackets under conditions

I have the file sed1.txt and I need to strip the brackets (]) and content inside them only when I have two or three letters followed by a colon. for example,it may be any letter, not just abc ] ] #-- cat sed1.txt 1 ] FISICA 2 ]PORTUGUES 3 ] ]MATEMATICA 4 ]]INGLES ] 5 ]QUIMICA 6... (2 Replies)
Discussion started by: dperboni
2 Replies

2. Shell Programming and Scripting

Brackets

Hi all. i need a small help. i have written an exit code, which will check whether mo.sh is successful or not. if the status is >0 it will exit the shell. 1>Do you guys think it is a correct way to write? 2>what if i change the double bracket to single. how will it change the o/p. ... (1 Reply)
Discussion started by: sub
1 Replies

3. Shell Programming and Scripting

Delete text between square brackets and also delete those square brackets using sed or awk

Hi All, I have a text file which looks like this: computer programming systems engineering I want to get rid of these square brackets and also the text that is inside these brackets. So that my final text file looks like this: computer programming systems engineering I am using... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

4. Shell Programming and Scripting

How to get the value in the first brackets

Hello, I am trying to write a script using ksh. And I want to get the value within the first brackets of a string. For example: 14/04/11 11:35: 00 This is (nn) from the earth. Then i hope to get nn in this case. Can any one advise me how to implement it? Thank you very much! nn (2 Replies)
Discussion started by: n_n
2 Replies

5. Shell Programming and Scripting

How to delete expression in the brackets?

how to delete second part in the expression sshd using gsub function so that output look likes sshd. Thanks. (4 Replies)
Discussion started by: tkmmelvin
4 Replies

6. Shell Programming and Scripting

Get value between brackets

Hi I am having hard time getting this right and need some help. I Have several log files, and everyone contains the following 3 lines at the end: 4 ETW000 Disconnected from database. 4 ETW000 End of Transport (0000). 4 ETW000 date&time: 13.01.2011 - 08:03:28 I need to capture the value... (7 Replies)
Discussion started by: nimo
7 Replies

7. Shell Programming and Scripting

How to apply brackets?

Hi, I have a query term like this: $query="apple NOT banana AND fruits"; $query="a1 NOT prim1 AND a2 NOT a3 OR a5"; I want to apply brackets to the NOT terms and the output should be like this: $query="apple NOT (banana) AND fruits"; $query="a1 NOT (prim1) AND a2 NOT (a3) OR a5";... (2 Replies)
Discussion started by: vanitham
2 Replies

8. Shell Programming and Scripting

how do you use brackets ?? in a script.

:D i am pretty much new to scripting and don't want to pick up bad habits so I am trying to get myself to use brackets in my scripts since I plan on using them alot.. ! in this example of a script I wrote I can not figure out where the brackets go can anyone give me some insight into the use of... (3 Replies)
Discussion started by: moxxx68
3 Replies

9. UNIX for Dummies Questions & Answers

square brackets

I would like to substitute a phrase which contains square brackets. change TO how? Thanks (2 Replies)
Discussion started by: gilead29
2 Replies

10. Post Here to Contact Site Administrators and Moderators

Angle brackets

From the Apache thread in the Adanced forum: Thats because your browser interprets anything within angle brackets to be an HTML tag. You need to quote these brackets if you want them to appear correctly. The proper quotes are: &amp;lt; for < and &amp;gt; for > So, for example, you would have... (1 Reply)
Discussion started by: PxT
1 Replies
Login or Register to Ask a Question