I have the following (gnu) sed
script that is designed to parse another sed script and output individual commands on a separate line.
In words, this script should put a newline character after each semicolon ;
, except for the semicolons that are inside the match or wildcard command.
Sed script :
/^
/^$/b
/^[^\n;]*;?$/b
s_/^[^/]+/[^;s]*;?_&\n_; t printtopline
s/^\\(.)[^\1]+\1[^;s]*;?/&\n/;t printtopline
s/\;/\;\n/; t printtopline;
:printtopline
P;D;
For example, I tested it with the following file (actually adapted from @ctac_'s answer to one of my previous sed questions):
Input file:
:A;
/\n>/!{s/\n/ /;N;bA};
s/^>//g;P
D
bA;
Output
The above script creates the correct output, for example, the line /\n>/!{s/\n/ /;N;bA}; # join next line if not a sequence label
becomes:
/\n>/!{s/\n/ /;
N;
bA};
Question
, , script :
s/\;/\;\n/; t printtopline;
:printtopline
, t printtopline
. , , , , :printtopline
.
, t
b
, script :
/\n>/!{s/\n/ /;
N;bA};
info sed
, t
:
't LABEL'
Branch to LABEL only if there has been a successful 's'ubstitution
since the last input line was read or conditional branch was taken.
The LABEL may be omitted, in which case the next cycle is started.
t
, b
?