Sed, matching nested brackets and deleting


 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Sed, matching nested brackets and deleting
# 1  
Old 03-17-2013
Code Sed, matching nested brackets and deleting

1. The problem statement, all variables and given/known data:
I have to write a script using sed, which delete everything between curly brackets and the brackets themself. The brackets might be nested.

The input-file is:

aaa { bbb ccc { ddd eee } fff { ggg hhh } iii jjj } kkk { lll mmm } nnn ooo ppp

The output-file should be:

aaa kkk nnn ooo ppp

2. Relevant commands, code, scripts, algorithms:
The script should be written in sed.
Use of the pattern/hold space should be used economically, because for larger files the script still has to be usable.

3. The attempts at a solution (include all code and scripts):

I have tried a few things but usually only can delete the first pair of brackets.


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

University Gent, Gent, Belgium, Peter Dawyndt and C002718


Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
# 2  
Old 03-17-2013
An algorithm:

1) If pattern space (PS) contains an opening curly brace (OCB), substitute an OCB, followed by any other character other than an OCB and closing curly brace (CCB) any number of times, followed by a CCB, with null string globally. If not, stop processing the PS and output it.
2) Go to 1.

Convert it into a sed script and let us know.
# 3  
Old 03-22-2013
First, post the solution where you can delete the first pair of brackets and see if you got that logic right.

Once you get that logic right, you can figure out how to delete the other ones.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting lines on matching certain pattern

hi I have a large xml file from which i have taken few lines . In this file I have to find for the string </invoices> and check if the 3 rd line after this string does not begin with <portCode> ,then i have to delete the string </invoices> and the next line having the string </shippingBill>... (13 Replies)
Discussion started by: sunnyboy
13 Replies

2. Shell Programming and Scripting

Adding a backslash in front of square brackets with sed

I'm trying to convert this line: to \ with sed. This is what I have so far: sed -e 's/\]*\)\]/\\\\\/' but this still gives me . Any suggestions? (15 Replies)
Discussion started by: lehaste
15 Replies

3. Shell Programming and Scripting

sed should cut of everything include the brackets

Hi there! sed should cut of everything include the brackets ... 443,0.806362,0.67317,1.46563,14.8237(#/cm�) ... 5112,0.812411,0.67317,1.4831,14.1875(#/cm�) it should be ... 443,0.806362,0.67317,1.46563,14.8237 ... 5112,0.812411,0.67317,1.4831,14.1875 i try it several times with ...... (4 Replies)
Discussion started by: IMPe
4 Replies

4. Shell Programming and Scripting

Deleting a matching string(line) which is also in other lines

Hi, i need help with my shell script I have a file input.txt containing the following contents /. /usr /usr/share /usr/share/doc /usr/share/doc/wine /usr/share/doc/wine/copyright /usr/share/doc/wine/changelog.Debian.gz I need output as /usr/share/doc/wine /usr/share/doc/wine/copyright... (3 Replies)
Discussion started by: Amit0991
3 Replies

5. Shell Programming and Scripting

Deleting lines from a stream after matching a pattern

Hi, I have a requirement to to an ldapsearch and remove the shadow attributes in the output file. What I do is ldapsearch() | operation to remove shadow > FILE The ldapsearch gives output like this(with same line formation): objectClass: FSConfig objectClass: extensibleObject fsCAIP:... (10 Replies)
Discussion started by: lorzinian
10 Replies

6. Shell Programming and Scripting

Regex/egrep matching numbers in brackets

Experts: I don't know that regular expressions will ever be easy for me, so if one of you guru's could help out, I'd appreciate it. I'm trying to match a line in our syslog, but I can't figure out how to match a number inside a bracket. This is what I'm trying to match. "Jul 16 00:01:34... (2 Replies)
Discussion started by: jdveencamp
2 Replies

7. 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

8. Shell Programming and Scripting

strip the square brackets from a word using sed or var expansion

Hi, I am trying to strip out leading and trailing brackets from a word. for example, I have a value, in a file. I want to strip out the leading and trailing brackets it and should get the value Running. I am using the following statement but in vain. grep "Workflow run status:" <... (4 Replies)
Discussion started by: svajhala
4 Replies

9. Shell Programming and Scripting

Deleting part of a string enclosed in brackets

I use otool on OS X to figure out the shared libraries that a binary uses. I run this command: otool -L /Applications/Vidnik\ 0.13.0/Vidnik.app/Contents/MacOS/Vidnik And it returns an output similar to this: /Applications/Vidnik 0.13.0/Vidnik.app/Contents/MacOS/Vidnik:... (10 Replies)
Discussion started by: pcwiz
10 Replies

10. Shell Programming and Scripting

deleting files and folders matching criteria

Hello, I'm spendind hours trying to figure out how a script could remove files and folders older than 30days in a given volume (/dataVolumes/Booba.1.0). Within this volume, all users have their personal folder that starts with "RC-..", so the script should skip them for deletion. I will... (4 Replies)
Discussion started by: H3001
4 Replies
Login or Register to Ask a Question