Link to home
Start Free TrialLog in
Avatar of fabiano petrone
fabiano petroneFlag for Italy

asked on

perl script

Hello, Experts
I'm asking (if possible) a little code that makes some transformation on a given text.
I've some bibliographical records in this format:

000000369 FMT   L BK
000000369 LDR   L -----nls--22--------450-
000000369 100   L $$a20130829a--------km-y0itay50------ba
000000369 2001  L $$a<<L' >>Arte della grammatica$$fLorenzo Valla
000000369 210   L $$aMilano$$cArnoldo Mondadori Editore$$d1990
000000369 BAS   L $$a1
000000369 BAS   L $$a68
000000369 BAS   L $$aRECUPERO BONFIETTI
000000369 COP   L $$sMANMO$$fCB806$$cM/Valla/E1$$iGFC-7794$$j28/11/1992$$p18,08$$mBOOK$$z36$$tBATCH

000000371 FMT   L BK
000000371 LDR   L -----nls--22--------450-
000000371 100   L $$a20130829a--------km-y0itay50------ba
000000371 2001  L $$aManuscript liisting for the authors of classical and late antiquity$$fRobert E. Sinkewicz
000000371 210   L $$aToronto$$cPontifical Institute of Mediaeval Studies$$d1990
000000371 BAS   L $$a1
000000371 BAS   L $$a68
000000371 BAS   L $$aRECUPERO BONFIETTI
000000371 COP   L $$sMANMO$$fCB806$$cA Phil/Sin/1(III)$$iGFC-12073$$j28/10/2003$$p19$$mBOOK$$z36$$tBATCH

<etc..>

I'd like to isolate -with a script- two parts of it and separate them with a "|"

the 2 parts that I want to isolate are the following:

1) begins always with "2001  L $$a" and ends always with  a "$"
2) begins always with "BAS   L $$a" and end with a newline

continuing the previous example, from the 2 previous records I'd like to obtain something similar to:

<<L' >>Arte della grammatica|1|68|RECUPERO BONFIETTI
Manuscript liisting for the authors of classical and late antiquity|1|68|RECUPERO BONFIETTI
<etc..>

Thanks in advance for your precious help,
fabianope
Avatar of ozo
ozo
Flag of United States of America image

perl -ne '/2001\s+L \$\$a(.*?)\$/ && print "\n$1";/BAS\s+L \$\$a(.*?)$/ && print "|$1";' <<'<etc..>'
000000369 FMT   L BK
000000369 LDR   L -----nls--22--------450-
000000369 100   L $$a20130829a--------km-y0itay50------ba
000000369 2001  L $$a<<L' >>Arte della grammatica$$fLorenzo Valla
000000369 210   L $$aMilano$$cArnoldo Mondadori Editore$$d1990
000000369 BAS   L $$a1
000000369 BAS   L $$a68
000000369 BAS   L $$aRECUPERO BONFIETTI
000000369 COP   L $$sMANMO$$fCB806$$cM/Valla/E1$$iGFC-7794$$j28/11/1992$$p18,08$$mBOOK$$z36$$tBATCH

000000371 FMT   L BK
000000371 LDR   L -----nls--22--------450-
000000371 100   L $$a20130829a--------km-y0itay50------ba
000000371 2001  L $$aManuscript liisting for the authors of classical and late antiquity$$fRobert E. Sinkewicz
000000371 210   L $$aToronto$$cPontifical Institute of Mediaeval Studies$$d1990
000000371 BAS   L $$a1
000000371 BAS   L $$a68
000000371 BAS   L $$aRECUPERO BONFIETTI
000000371 COP   L $$sMANMO$$fCB806$$cA Phil/Sin/1(III)$$iGFC-12073$$j28/10/2003$$p19$$mBOOK$$z36$$tBATCH

<etc..>
Avatar of fabiano petrone

ASKER

Hello, ozo
thanks a lot for the reply.
is it possible to put this code inside a little script that I call from a console like 'script.pl <input.txt>output.txt'?

thanks again,

fabianope
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Super-Thanks!! :=))