The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
why put double square brackets in an if clause? napolayan UNIX for Dummies Questions & Answers 5 11-16-2006 03:18 AM
usage of brackets for if lakshmikanth UNIX for Dummies Questions & Answers 4 07-28-2006 09:03 AM
how do you use brackets ?? in a script. moxxx68 Shell Programming and Scripting 3 09-27-2004 10:57 PM
square brackets gilead29 UNIX for Dummies Questions & Answers 2 02-03-2004 11:29 AM
Angle brackets PxT Post Here to Contact Site Administrators and Moderators 1 04-05-2001 06:06 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-18-2008
kamel.seg kamel.seg is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 57
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 (permalink)  
Old 01-18-2008
Tytalus's Avatar
Tytalus Tytalus is online now Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
You could try tr:
e.g.
Code:
 echo "Q[xxxx]" | tr -d "[]"
or
Code:
echo "Q[xxxx]" < file
  #3 (permalink)  
Old 01-18-2008
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,628
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 (permalink)  
Old 01-18-2008
kamel.seg kamel.seg is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 57
thanks but
i need a command for all the file cause a have many cases like Q[xxx]...
  #5 (permalink)  
Old 01-18-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
Quote:
Originally Posted by kamel.seg View Post
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0