Selecting section and removing match


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Selecting section and removing match
# 1  
Old 02-07-2020
Selecting section and removing match

I have a file with contents as shown in file.texi

Would like to keep only the sections that have inlineifset till the empty line is reached. Finally replace the
following string with a space

Code:
@inlineifset{mrg, @opar{@bullet{}

I had written the following command but it messed my file

Code:
sed 's/inlineifset/,/^ *$/p' $flnm |\
  sed 's/@inlineifset\{mrg\, @opar\{@bullet\{\} //g' > ch--outline.texi

The result should be

Code:
@subsubsection ObsPy LibmSeed License Problem,,,,}}

@inlineifset{mrg, @opar{@point{} ObsPy [LibmSeed];, Problems Merging
Codes;, Hard to package and release software;, Practices in Seismology
require careful thought,}}

@inlineifset{mrg, @opar{@point{} ObsPy [LibmSeed];, Problems Merging
Codes;, Hard to package and release software;, Practices in Seismology
require careful thought,}}

@inlineifset{mrg, @opar{+ ObsPy LibmSeed Routines;, libmseed-2.6.2:
obspy-readbuffer.c packdata.c unpackdata.c;, Pack Routines taken from
qlib2;, Incompatible Licenses.,}}

Code:
cat file.texi

@node ObsPy--ObsPy--LibmSeed--LicProblem
@subsubsection ObsPy LibmSeed License Problem

@inlineifset{mrg, @opar{@bullet{} @subsubsection ObsPy LibmSeed License Problem,,,,}}

@inlineifset{mrg, @opar{@point{} ObsPy [LibmSeed];, Problems Merging
Codes;, Hard to package and release software;, Practices in Seismology
require careful thought,}}

The developers of ObsPy had taken a step in the right direction by
promoting principled, community minded seismological computations.
However, the @emph{LibmSeed} story exposes the problems that can be
encountered when merging code from a large number of other packages into
ObsPy.  This situation shows how hard it is to package and release
software.  As a result, practices in seismology require careful thought.
If such thought is not done, the problems will get much worse,
especially for future seismological work and for succeeding generations.

A relevant illustrative example is ObsPy, a framework for processing
seismology data that has become popular with students.  However, its
philosophy of rapid development is today progressing without forethought
and good practice, as evidenced by the @emph{LibmSeed} license problem.
In fact, Till 2016, obspy was not legally suitable for source release as
it was, unless libmseed was stripped from it.

@c @section ObsPy Framework for Processing Seismological Data.

@inlineifset{mrg, @opar{@point{} ObsPy [LibmSeed];, Problems Merging
Codes;, Hard to package and release software;, Practices in Seismology
require careful thought,}}

@inlineifset{mrg, @opar{+ ObsPy LibmSeed Routines;, libmseed-2.6.2:
obspy-readbuffer.c packdata.c unpackdata.c;, Pack Routines taken from
qlib2;, Incompatible Licenses.,}}

Developers of the Python Framework for Processing Seismological Data
(ObsPy) have taken a step in the right direction by promoting
principled, community-minded seismological computations.  Particularly
important was the replacement of the pack routines in the ObsPy
Mini-Seed Library called LibmSeed.  The library is a framework for
manipulating the @emph{Standard for the Exchange of Earthquake Data}
[Seed] Data Records.  There were two source files involved, namely,
@file{packdata.c} and @file{unpackdata.c}; both taken from the
@code{qlib2} library developed by Berkeley Seismological Laboratory
Information Systems Manager Douglas Neuhauser
@uref{http://www.ncedc.org/qug/software/ucb/}.  The two routines were
called from @code{obspy/io/mseed/src/libmseed/obspy-readbuffer.c}, The
modifications were done and released by Chad Trabant @minus @ Deputy
Director for Projects at Iris @minus @ in Version 2.6.2 of LibmSeed
tagged on GitHub as @code{libmseed-2.6.2} on Sep 23, 2016.  The problem
originated from the incompatible terms of the GNU Lesser General Public
License (LGPL) and the University of California Berkeley License.  The
explicit restriction from commercial use made the software source code
proprietary, contradicting the usage terms of the LGPL.  Till then,
ObsPy was not legally suitable for source release as it was, unless
LibmSeed was stripped from it.


Last edited by Danette; 02-07-2020 at 06:09 PM..
# 2  
Old 02-07-2020
Try - remember you wanted a space! -

Code:
$ awk '/inlineifset/ {sub (/@inlineifset{mrg, @opar{@bullet{}/, " "); print}' RS= ORS="\n\n" file
  @subsubsection ObsPy LibmSeed License Problem,,,,}}

@inlineifset{mrg, @opar{@point{} ObsPy [LibmSeed];, Problems Merging
Codes;, Hard to package and release software;, Practices in Seismology
require careful thought,}}

@inlineifset{mrg, @opar{@point{} ObsPy [LibmSeed];, Problems Merging
Codes;, Hard to package and release software;, Practices in Seismology
require careful thought,}}

@inlineifset{mrg, @opar{+ ObsPy LibmSeed Routines;, libmseed-2.6.2:
obspy-readbuffer.c packdata.c unpackdata.c;, Pack Routines taken from
qlib2;, Incompatible Licenses.,}}

This User Gave Thanks to RudiC For This Post:
# 3  
Old 02-08-2020
It would be good to also remove the ,,,,}} of the sections commands.


A command that has also worked is

Code:
sed -n '/inlineifset/,/^ *$/p' $flnm |\
  sed 's/@inlineifset{mrg, @opar{@bullet{} @//g' >> $ofln

# 4  
Old 02-08-2020
Hi
no pipe needed
Code:
sed '/inlineifset/,/^ *$/!d; s/@inlineifset{mrg, @opar{@bullet{} @//' $flnm

This User Gave Thanks to nezabudka For This Post:
# 5  
Old 02-08-2020
Ok, I found I can also write the commands on multiple lines

Code:
sed '/inlineifset/,/^ *$/!d; s/@inlineifset{mrg, @opar{@bullet{} @//' $flnm

is then rewritten as


Code:
 sed '/inlineifset/,/^ *$/!d;
  s/@inlineifset{mrg, @opar{@bullet{} @//' $flnm

When I find



Code:
@inlineifset{mrg, @opar{@bullet{} @@subsection Complications of External
Dependencies,,,,}}

I want to put things in one line and also remove the ,,,,}} at the end


Code:
@subsection Complications of External Dependencies


Last edited by Danette; 02-08-2020 at 01:16 PM..
# 6  
Old 02-08-2020
How about


Code:
awk '/inlineifset/ {gsub (/@inlineifset{mrg, @opar{@bullet{} |,,,,}}/, ""); print}' RS= ORS="\n\n" file

or, if you insist on sed,



Code:
sed '/inlineifset/,/^ *$/!d; s/@inlineifset{mrg, @opar{@bullet{} \(.*\),,,,}}/\1/' file

# 7  
Old 02-08-2020
I am going to stop this here as it actually answers the original task.

Last edited by Danette; 02-08-2020 at 04:28 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Selecting text on multiple lines, then removing a beginning and end patterns

I have a file similar to the below. I am selecting only the paragraphs with @inlineifset. I am using the following command sed '/@inlineifset/,/^ *$/!d; s/@inlineifset{mrg, @btpar{@//' $flnm >> $ofln This produces @section Correlations between seismograms,,,,}} ... (5 Replies)
Discussion started by: Danette
5 Replies

2. Shell Programming and Scripting

Comparing two one-line files and selecting what does not match

I have two files. One is consisting of one line, with data separated by spaces and each number appearing only once. The other is consisting of one column and multiple lines which can have some numbers appearing more than once. It looks something like this: file 1: 20 700 15 30 file2: 10... (10 Replies)
Discussion started by: maya3
10 Replies

3. Shell Programming and Scripting

Removing section from tnsnames.ora

Hi, I am trying to write a script or command to remove a section from tnsnames.ora file in the following example I would like to remove tns_alias2 section $ cat tnsnames.ora tns_alias1 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = host1 )(PORT = 1521)) ... (3 Replies)
Discussion started by: ynixon
3 Replies

4. Shell Programming and Scripting

Perl removing line match with pattern in column

Hi, I have log like this: ... (1 Reply)
Discussion started by: justbow
1 Replies

5. Shell Programming and Scripting

Selecting nearest pattern match

I'm looking to match an error code against a list of possible codes and get the nearest match. The code would be a 6 character hexadecimal string. I have a file of error codes all of which have a specific first 3 characters, however, after that the last 3 characters may be specific or generic as... (3 Replies)
Discussion started by: dazedandconfuse
3 Replies

6. UNIX for Dummies Questions & Answers

Removing duplicate rows & selecting only latest date

Gurus, From a file I need to remove duplicate rows based on the first column data but also we need to consider a date column where we need to keep the latest date (13th column). Ex: Input File: Output File: I know how to take out the duplicates but I couldn't figure out... (5 Replies)
Discussion started by: shash
5 Replies

7. Shell Programming and Scripting

Extract section of file based on word in section

I have a list of Servers in no particular order as follows: virtualMachines="IIBSBS IIBVICDMS01 IIBVICMA01"And I am generating some output from a pre-existing script that gives me the following (this is a sample output selection). 9/17/2010 8:00:05 PM: Normal backup using VDRBACKUPS... (2 Replies)
Discussion started by: jelloir
2 Replies

8. Shell Programming and Scripting

Removing file lines that each match to a different patterns

I have a very large file (10,000,000 lines), that contains a sample id and a property of that sample. I have another file that contains around 1,000,000 lines with sample ids that I want to remove from the original file (create a new file without these lines). I know how to do this in Perl, but it... (9 Replies)
Discussion started by: Jo_puzzled
9 Replies

9. Shell Programming and Scripting

Selecting A Section of A File Based On the Time Within It

Hi, I have a file formated like this: John 7.22 2010-01-25_17:01:36 George 8.22 2010-01-25_17:02:36 Bob 9.62 2010-01-25_17:04:36 Jane 10.11 2010-01-25_17:05:36 Emma 4.52 2010-01-25_17:01:36 What I want to do is cut out only the entries that have... (2 Replies)
Discussion started by: Donkey25
2 Replies

10. Shell Programming and Scripting

Removing Duplicate Lines per Section

Hello, I am in need of removing duplicate lines from within a file per section. File: ABC1 012345 header ABC2 7890-000 ABC3 012345 Header Table ABC4 ABC5 593.0000 587.4800 ABC5 593.5000 587.6580 <= dup need to remove ABC5 593.5000 ... (5 Replies)
Discussion started by: petersf
5 Replies
Login or Register to Ask a Question