LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-08-2018, 03:32 PM   #1
nirvaanr
LQ Newbie
 
Registered: Jun 2016
Distribution: Debian 10
Posts: 26

Rep: Reputation: Disabled
Smile shell script to remove the text between all curly brackets from text file


Hello experts,

I have a text file with lot of curly brackets (both opening { & closing } ). I need to delete them alongwith the text between opening & closing brackets' pair.

For ex: Input:-

Code:
59. Rh1 Qe4 {(Qf5-e4 Qd8-g8+ Kg6-f5
Qg8-h7+ Kf5-e5 Qh7-e7+ Ke5-f5 Qe7-d7+ Qe4-e6 Qd7-h7+ Qe6-g6 Qh7-h3+ Kf5-f6
Qh3-c3+ Kf6-f7 Qc3-b3+ Kf7-f6 Qb3-b6+ Kf6-f7 Qb6-b7+ Kf7-f6 Qb7-c6+ Kf6-f7
Qc6-d7+ Kf7-f6 Rh1-h8 Qg6-g7 Qd7-c6+ Kf6-f5 Qc6xc5+ Bf4-e5 Rh8-h7 Qg7-g6
Qc5-c2+ Kf5-f6 Qc2-c6+ Kf6-f5 Qc6-f3+ Be5-f4 Qf3-h3+ g5-g4 Qh3-d3+ Kf5-f6
Qd3-d8+ Kf6-f5 Qd8-d5+ Kf5-f6 Rh7-h8 Bf4-e5 Rh8-f8+ Kf6-e7 Qd5-d8+ Ke7-e6
Rf8-e8+ Qg6xe8 Qd8xe8+ Ke6-f5 Qe8-d7+ Kf5-g5 Qd7-d8+ Kg5-f5 Qd8xa5 Kf5-f4
Qa5-d2+ Kf4-g3 Qd2-e3+ Kg3-g2 Qe3xe5 g4-g3) -132.53/42 7} 60. Qg8+
{(Qd8-g8+ Kg6-f5 Qg8-h7+ Kf5-e5 Qh7-e7+ Ke5-f5 Qe7-d7+ Qe4-e6 Qd7-h7+
Qe6-g6 Qh7-h3+ Kf5-f6 Qh3-c3+ Kf6-f7 Qc3-b3+ Kf7-f6 Qb3-b6+ Kf6-g7 Qb6-b7+
Kg7-f6 Qb7-c6+ Kf6-g7 Qc6-d7+ Kg7-f6 Rh1-h8 Qg6-g7 Qd7-c6+ Kf6-f5 Qc6xc5+
Bf4-e5 Rh8-h7 Qg7-g6 Qc5-f2+ Kf5-g4 Qf2-e2+ Kg4-f5 Qe2-d3+ Kf5-f6 Qd3-f3+
Be5-f4 Qf3-c6+ Kf6-f5 Qc6-c8+ Kf5-e5 Rh7-e7+ Ke5-d5 Qc8-d7+ Bf4-d6 Qd7-b5+
Kd5-d4 Qb5-c6 Bd6xe7 Qc6xg6 Kd4-e5 Qg6-e8 Ke5-d6 Qe8-b8+ Kd6-c6 Qb8-c8+
Kc6-d5 Qc8-f5+ Kd5-d4 Qf5xa5 Kd4-c4) +132.53/37 4} Kf5


Then the expected output:-

Code:
59. Rh1 Qe4 60. Qg8+ Kf5
I tried sed and awk but failed to do so as I'm not at all good with them. Please help!

Many Thanks!!
 
Old 07-08-2018, 04:31 PM   #2
nirvaanr
LQ Newbie
 
Registered: Jun 2016
Distribution: Debian 10
Posts: 26

Original Poster
Rep: Reputation: Disabled
I got a solution from here - https://www.unix.com/shell-programmi...#post303019848
 
Old 07-10-2018, 01:59 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,258
Blog Entries: 3

Rep: Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713
The example in the link could use a little work on a whitespace problem in its output.

Can you please elaborate a little on what your solution turned out to be? And how well did it work for your full data set?
 
Old 07-10-2018, 05:50 AM   #4
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,879

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
The two solutions of Chubler_XL produce results with two lines:
Code:
59. Rh1 Qe4  60. Qg8+
 Kf5
The "expected output" posted by OP was one line:
Code:
59. Rh1 Qe4 60. Qg8+ Kf5
A single-line result may be obtained with this code:
Code:
tr " " "\n" <$InFile  \
|sed "/{/,/}/d"       \
|paste -s -d' ' -     \
>$OutFile
Daniel B. Martin

.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash - Remove multiple brackets and text inside it from filename Springs Linux - Newbie 6 03-15-2018 07:21 AM
[SOLVED] Shell script to remove selected line number from text file. ChocaMocha Programming 4 04-25-2013 03:11 PM
Cannot read text from text file and store it in a variable using shell script anurupr Linux - Newbie 2 03-03-2010 01:38 PM
Shell script:- Reading numbers embedded in brackets from a text file rsan Linux - Newbie 6 07-05-2009 06:01 AM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration