find and replace


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find and replace
# 1  
Old 09-25-2011
find and replace

Hi All,

I have a file with a succesion of records like this:

Code:
=LDR  00943nas  2200241 i 4500
=005  20110318131920.0
=008  920528c1965\\\\-usqr\p\r\\\\\0\\\\\eng\d
=022  0\$a0002-9262
=022  \\$a1476-6256 (online)
=041  0\$aeng
=210  1\$aAm J Epidemiol
=245  00$aAmerican Journal of Epidemiology / $cSchool of Hygiene and Public Health of The Johns Hopkins University.
=260  \\$aBaltimore : $bAmerican Journal of Epidemiology, $c1965.
=270  \\$a624 N.Broadway, Room 225
=300  \\$c23 cm.
=310  \\$aMensual
=530  \\$aDisponible en versi{dbldotb}n electr{dbldotb}nica desde 1996.
=650  \4$aEpidemiolog{rcommaa}a.
=780  00$aEs continuaci{dbldotb}n de. $tAmerican Journal of Hygiene $xISSN 0096-5294
=856  \\$uhttp://aje.oxfordjournals.org/?code=aje&.cgifields=code $zAcceso al texto completo
=952  \\$aBNCSMAJ $bBNCSMAJ $h1965-75(1976-77)1978-94(1995 $yJNL $oBNCSMAJ0000001 $pBNCSMAJ0000001

I would like to replace the line starting with =856 with different values
first value will be, the first value of the fields 952 $a and $b => this one \\$aBNCSMAJ\\$bBNCSMAJ
Then a fix value (always the same) => $yEJNL
And at the end, this two values also picked from 952 field:
\\$oBNCSMAJ0000001\\$pBNCSMAJ0000001

As a resulta the entire record will be:
Code:
=LDR  00943nas  2200241 i 4500
=005  20110318131920.0
=008  920528c1965\\\\-usqr\p\r\\\\\0\\\\\eng\d
=022  0\$a0002-9262
=022  \\$a1476-6256 (online)
=041  0\$aeng
=210  1\$aAm J Epidemiol
=245  00$aAmerican Journal of Epidemiology / $cSchool of Hygiene and Public Health of The Johns Hopkins University.
=260  \\$aBaltimore : $bAmerican Journal of Epidemiology, $c1965.
=270  \\$a624 N.Broadway, Room 225
=300  \\$c23 cm.
=310  \\$aMensual
=530  \\$aDisponible en versi{dbldotb}n electr{dbldotb}nica desde 1996.
=650  \4$aEpidemiolog{rcommaa}a.
=780  00$aEs continuaci{dbldotb}n de. $tAmerican Journal of Hygiene $xISSN 0096-5294
=856  \\$aBNCSMAJ $bBNCSMAJ$yEJNL\\$oBNCSMAJ0000001\\$pBNCSMAJ0000001
=952  \\$aBNCSMAJ $bBNCSMAJ $h1965-75(1976-77)1978-94(1995 $yJNL $oBNCSMAJ0000001 $pBNCSMAJ0000001

I hope there is a way to do this.
Thanks a lot for any help
# 2  
Old 09-25-2011
Hi ldiaz2106,

Try:
Code:
$ cat infile
=LDR  00943nas  2200241 i 4500
=005  20110318131920.0
=008  920528c1965\\\\-usqr\p\r\\\\\0\\\\\eng\d
=022  0\$a0002-9262
=022  \\$a1476-6256 (online)
=041  0\$aeng
=210  1\$aAm J Epidemiol
=245  00$aAmerican Journal of Epidemiology / $cSchool of Hygiene and Public Health of The Johns Hopkins University.
=260  \\$aBaltimore : $bAmerican Journal of Epidemiology, $c1965.
=270  \\$a624 N.Broadway, Room 225
=300  \\$c23 cm.
=310  \\$aMensual
=530  \\$aDisponible en versi{dbldotb}n electr{dbldotb}nica desde 1996.
=650  \4$aEpidemiolog{rcommaa}a.
=780  00$aEs continuaci{dbldotb}n de. $tAmerican Journal of Hygiene $xISSN 0096-5294
=856  \\$uhttp://aje.oxfordjournals.org/?code=aje&.cgifields=code $zAcceso al texto completo
=952  \\$aBNCSMAJ $bBNCSMAJ $h1965-75(1976-77)1978-94(1995 $yJNL $oBNCSMAJ0000001 $pBNCSMAJ0000001
$ cat script.pl
use warnings;
use strict;

while ( <> ) {
        next if m/\A=856/;
        chomp;

        if ( m/\A=952/ ) {
                my @f = split;
                printf "=856  %s\n%s\n", 
                        join( q[\\\\], $f[1] . qq[ ] . $f[2] . q[$yEJNL], $f[$#f-1], $f[$#f] ),
                        $_;

                next;
        }

        printf "%s\n", $_;
}
$ perl script.pl infile
=LDR  00943nas  2200241 i 4500
=005  20110318131920.0
=008  920528c1965\\\\-usqr\p\r\\\\\0\\\\\eng\d
=022  0\$a0002-9262
=022  \\$a1476-6256 (online)
=041  0\$aeng
=210  1\$aAm J Epidemiol
=245  00$aAmerican Journal of Epidemiology / $cSchool of Hygiene and Public Health of The Johns Hopkins University.
=260  \\$aBaltimore : $bAmerican Journal of Epidemiology, $c1965.
=270  \\$a624 N.Broadway, Room 225
=300  \\$c23 cm.
=310  \\$aMensual
=530  \\$aDisponible en versi{dbldotb}n electr{dbldotb}nica desde 1996.
=650  \4$aEpidemiolog{rcommaa}a.
=780  00$aEs continuaci{dbldotb}n de. $tAmerican Journal of Hygiene $xISSN 0096-5294
=856  \\$aBNCSMAJ $bBNCSMAJ$yEJNL\\$oBNCSMAJ0000001\\$pBNCSMAJ0000001
=952  \\$aBNCSMAJ $bBNCSMAJ $h1965-75(1976-77)1978-94(1995 $yJNL $oBNCSMAJ0000001 $pBNCSMAJ0000001

Regards,
Birei
# 3  
Old 09-25-2011
Hi
Thanks a lot for this script.
I try it with a sample and here is the result:
First, if I redirect to a new file I have this:

Code:
ubuntu@ip-10-235-33-163:~$ perl 856.pl text1.txt >text2.txt
Use of uninitialized value in concatenation (.) or string at 856.pl line 10, <> line 15.
Use of uninitialized value in concatenation (.) or string at 856.pl line 10, <> line 32.
Use of uninitialized value in concatenation (.) or string at 856.pl line 10, <> line 46.
Use of uninitialized value in concatenation (.) or string at 856.pl line 10, <> line 47.
Use of uninitialized value in concatenation (.) or string at 856.pl line 10, <> line 64.
Use of uninitialized value in concatenation (.) or string at 856.pl line 10, <> line 82.
Use of uninitialized value in concatenation (.) or string at 856.pl line 10, <> line 83.
Use of uninitialized value in concatenation (.) or string at 856.pl line 10, <> line 84.

Not sure it's a problem, then if you look the new file:
You see this

Code:
.....
=780  00$aEs continuaci{dbldotb}n de. $t"Journal of Medical Education" $xISSN 0022-2577
=856  \\$aBNCS-CH\\$bBNCS-CH\\$h1989\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL $yEJNL\\=952\\\\$aBNCS-CH\\$bBNCS-CH\\$h1989\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL
=952 \\$aBNCS-CH\\$bBNCS-CH\\$h1989\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL

The exact result should be this:

Code:
...
=780  00$aEs continuaci{dbldotb}n de. $t"Journal of Medical Education" $xISSN 0022-2577
=856  \\$aBNCS-CH\\$bBNCS-CH\\$h1989\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL $yEJNL
=952 \\$aBNCS-CH\\$bBNCS-CH\\$h1989\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL

The difference is is 856 field there is the 952 field too...Not good
Is it possible to change this?
Thanks again for all the effort

---------- Post updated at 10:06 AM ---------- Previous update was at 08:15 AM ----------

Hi Alister

yes I'll give here some explication, sorry not be enougth clear in my last posts.
So the file is a succesion of records.
Each record starts with this field:
Code:
=LDR

And the into each record you'll see a lot of =xxx codes
The code I want to change are =856 and =866
All this lines starting with =856 and =866 code may be change to be =952
But, the traitment is not the same if we have =866 or =856
The =866 case is resolve with some nice nawk command given yesterday:

Code:
nawk -F"[\$a ]" '{if ($0~/^=866/) {print "=952",$3"$a"$5$3"$b"$5"\\\\$h"$6"\\\\$o"$5"0000001\\\$p"$5"0000001\\\\$yJNL" } else {print $0}}' test.txt

As you see, this command line just change the =866 code
The =856 code is different because the data are not present in the line, it can not be catched with awk pointing to the write column.
The data are spraid between new =952 code
So the way I change is:

apply the
Code:
nawk -F"[\$a ]" '{if ($0~/^=866/) {print "=952",$3"$a"$5$3"$b"$5"\\\\$h"$6"\\\\$o"$5"0000001\\\$p"$5"0000001\\\\$yJNL" } else {print $0}}' test.txt

command line

After this step, I have a new file with =952 for all the occurence of =866 code.
I have a 3 step which be modify the =856

All the fileds in a same line are separated bu \\$letter
letter could be any letter in the alphabet, in my case we have \\$a \\$b \\$y \\$h \\$o and \\$p

The code posted just earlier in good but just whit one duplication:
Code:
use warnings; use strict;  while ( <> ) {         next if m/\A=856/;         chomp;          if ( m/\A=952/ ) {                 my @f = split;                 printf "=856  %s\n%s\n",                          join( q[\\\\], $f[1] . qq[ ] . $f[2] . q[$yEJNL], $f[$#f-1], $f[$#f] ),                         $_;                  next;         }          printf "%s\n", $_; }

It change fine the =856 code, but add =952 in the same line..That is not write.

The entire file is very long, so here I'll send just a sample and after the resulta I would like to have:

Original sample:

Code:
=LDR  00795nas  2200193 i 4500
=005  20100728125529.0
=008  920520c1989\\\\-usmr\\\\\\\\\0\\\\\eng\\
=022  0\$a1040-2446
=041  0\$aeng
=210  1\$aAcad Med
=245  00$aAcademic Medicine / $cAssociation of American Medical Colleges.
=260  \\$aPhiladelphia : $bAssociation American Medical Colleges, $c1989.
=300  \\$c24 cm.
=310  \\$aMensual
=530  \\$aDisponible en versi{dbldotb}n electr{dbldotb}nica desde 2000.
=650  \4$aMedicina.
=780  00$aEs continuaci{dbldotb}n de. $t"Journal of Medical Education" $xISSN 0022-2577
=856  \\$uhttp://ovidsp.ovid.com/ovidweb.cgi?T=JS&MODE=ovid&NEWS=n&PAGE=toc&D=ovft&AN=00001888-000000000-00000   $zAcceso al texto completo
=866  \\$aBNCS-CH 1989 (1990)1991(1992)1993-96(1997)1998-2001(2002-2005)2006-2008.

=LDR  00901nas  2200205 i 4500
=005  20061017111721.0
=008  920528d19721998sp\br\p\r\\\\\0\\\a\spa\d
=022  0\$a0300-5062
=041  0\$aspa
=210  0\$aActas Luso Esp Neurol Psiquiatr Cienc Afines
=245  00$aActas Luso Espa{ogon}olas de Neurolog{rcommaa}a, Psiquiatr{rcommaa}a y Ciencias Afines /$cGrupo para el progreso de la Psiquiatria.
=260  \\$aMadrid : $bGarsi, $c1972-1998.
=270  \\$aLondres 17. 28028 Madrid
=300  \\$c26 cm.
=310  \\$aBimensual
=525  \\$aTiene como suplemento: "Actas Luso Espa{ogon}olas de Neurolog{rcommaa}a, Psiquiatr{rcommaa}a y Ciencias Afines. Suplemento", ISSN, 1137-604X.
=650  14$aPsiquiatr{rcommaa}a.
=780  00$aEs continuaci{dbldotb}n de. $tActas luso-espa{ogon}olas de neurolog{rcommaa}a y psiquiatr{rcommaa}a$xISSN 0001-7329
=785  00$cContinuada por$tActas Espa{ogon}olas de Psiquiatr{rcommaa}a $xISSN 1139-9287
=866  \\$aBNCS-CH (1988-1989)1990-91(1992)1993(1994)1995-97(1998).

=LDR  00558nas  2200169 i 4500
=005  20110317114649.0
=008  920528c1949\\\\spamr\p\\\\\\\0\\\\\spa\d
=022  0\$a0001-6519
=041  1\$aspa
=210  1\$aActa Otorrinolaringol Esp
=245  00$aActa otorrinolaringol{dbldotb}gica espa{ogon}ola / $cSociedad Espa{ogon}ola de Otorrinolaringolog{rcommaa}a y Patologia C{caron}rvico-Facial.
=260  \\$aMadrid : $bGarsi, $c1949.
=270  \\$aC/ Londres, 17 28028 Madrid
=300  \\$c27 cm.
=310  \\$aBimestral
=650  \4$aMedicina-$xEspecialidades.
=866  \\$aBNCS-CH (1989-90)1991-97(1998),1999-2006.

=LDR  00503nas  2200181 i 4500
=005  20030814120145.0
=008  920528d1984\\\\sp\mr\pr\\\\\\0\1\a\spa\d
=022  0\$a0213-0580
=041  1\$aspa
=210  1\$aActa Paediatr Scand (Ed Esp)
=245  00$aActa paediatrica scandinavica / $cSaned.
=250  \\$aEdicion en espa{ogon}ol.
=260  \\$aMadrid : $bSANED, $c1984.
=270  \\$aApolonio Morales, 6. 28036 Madrid
=300  \\$c27 cm.
=310  \\$aBimestral
=650  \4$aPediatr{rcommaa}a.
=866  \\$aBNCS-CH 1984-86,(1991-92).

=LDR  00627nas  2200181 i 4500
=005  20110317121830.0
=008  920528c1945\\\\sp\mr\p\p\\\\\0\\\\\spa\d
=022  0\$a0001-6640
=041  0\$aspa
=210  1\$aActa Pediatr Esp
=245  10$aActa pedi{grave}trica espa{ogon}ola / $cSaned.
=260  \\$aMadrid : $bSaned, $c1945-
=270  \\$aApolonio Morales, 6.28036 Madrid
=300  \\$c26 cm.
=310  \\$aMensual
=650  \4$aPediatr{rcommaa}a.
=780  00$aEs continuaci{dbldotb}n de. $tActa pedi{grave}trica (Madrid), ISSN 0301-5203
=866  \\$aBNCS-CH (1945),(1948-49),(1951-52),(1955),(1964),(1967-68),1970-77(1978)1979-82(1983-87)1988-93(1994)1995-96(1997-98)1999-2010.

=LDR  00445nas  2200169 i 4500
=005  20030814120318.0
=008  920528c1958\\\\sp\sr\p\\\\\\\0\\\\\spa\d
=022  0\$a0011-7655
=041  0\$aspa
=210  1\$aActual Econ
=245  10$aActualidad econ{dbldotb}mica / $cPunto Editorial.
=260  \\$aMadrid : $bPunto Editorial, $c1958.
=270  \\$aP{eth} Recoletos,1. 18001 Madrid
=300  \\$c27 cm.
=310  \\$aSemanal
=650  \4$aEconom{rcommaa}a.
=866  \\$aBNCS-CH (1985-94).

=LDR  00798nas  2200181 i 4500
=005  20091124134137.0
=008  920528c1973\\\\sp\br\p\\\\\\\0\11a\mul\d
=022  0\$a0301-0546
=041  1\$amul
=210  1\$aAllergol Immunopathol (Madr)
=245  00$aAllergologia et immunopathologia / $cSociedad Espa{ogon}ola de Alergia e Inmunolog{rcommaa}a Cl{rcommaa}nica ; Sociedad Latinoamericana de Alergia e Inmunolog{rcommaa}a ; International Association of Asthmology ; Asociaci{dbldotb}n de Inmunolog{rcommaa}a Clinica y Alergolog{rcommaa}a Pediatrica.
=260  \\$aBarcelona : $bDoyma, $c1973.
=300  \\$c27 cm.
=310  \\$aBimestral
=525  \\$aTiene como suplemento: Allergolog{rcommaa}a et Immunopatholog{rcommaa}a. Supllementum, ISSN 0211-6448.
=650  \4$aMedicina-$xEspecialidades.
=866  \\$aBNCS-CH (1988)1989(1990-91)1992-98(1999)2003-
=866  \\$aBNCS-C.UNIV 1974-77.

=LDR  00782nas  2200205 i 4500
=005  20110125160214.0
=008  920528c1974\\\\-usqr\p\r\\\\\0\\\a\eng\d
=022  0\$a0095-2990
=022  \\$a1097-9891 (online)
=041  0\$aeng
=210  0\$aAm J Drug Alcohol Abuse
=245  00$aAmerican journal of drug alcohol abuse / $cThe American Academy of Psychiatrists in Alcoholism & Addictions.
=260  \\$aNew York : $bMarcel Dekker, $c1974.
=270  \\$a270 Madison Avenue, New York 10016
=300  \\$c25 cm.
=310  \\$aTrimestral
=530  \\$aDisponible en versi{dbldotb}n electr{dbldotb}nica  1999-2008.
=650  \4$aDependencia a sustancias nocivas.
=856  \\$uhttps://www.swetswise.com/eAccess/viewTitleIssues.do?titleID=9055&year=2008   $zAcceso al texto completo
=866  \\$aBNCS-CH1989-96,1998-2008.

=LDR  00943nas  2200241 i 4500
=005  20110318131920.0
=008  920528c1965\\\\-usqr\p\r\\\\\0\\\\\eng\d
=022  0\$a0002-9262
=022  \\$a1476-6256 (online)
=041  0\$aeng
=210  1\$aAm J Epidemiol
=245  00$aAmerican Journal of Epidemiology / $cSchool of Hygiene and Public Health of The Johns Hopkins University.
=260  \\$aBaltimore : $bAmerican Journal of Epidemiology, $c1965.
=270  \\$a624 N.Broadway, Room 225
=300  \\$c23 cm.
=310  \\$aMensual
=530  \\$aDisponible en versi{dbldotb}n electr{dbldotb}nica desde 1996.
=650  \4$aEpidemiolog{rcommaa}a.
=780  00$aEs continuaci{dbldotb}n de. $tAmerican Journal of Hygiene $xISSN 0096-5294
=856  \\$uhttp://aje.oxfordjournals.org/?code=aje&.cgifields=code $zAcceso al texto completo
=866  \\$aBNCS-CH 1971-75(1976)1977-2003(2004)2005-
=866  \\$aBNCS-C.UNIV 1990-93(1994)1995-2001.
=866  \\$aBNCS-MAJ 1965-75(1976-77)1978-94(1995).

After applying the first step I have:
(you will see the field 856 only because 866 have been changed)

Code:
=LDR  00795nas  2200193 i 4500
=005  20100728125529.0
=008  920520c1989\\\\-usmr\\\\\\\\\0\\\\\eng\\
=022  0\$a1040-2446
=041  0\$aeng
=210  1\$aAcad Med
=245  00$aAcademic Medicine / $cAssociation of American Medical Colleges.
=260  \\$aPhiladelphia : $bAssociation American Medical Colleges, $c1989.
=300  \\$c24 cm.
=310  \\$aMensual
=530  \\$aDisponible en versi{dbldotb}n electr{dbldotb}nica desde 2000.
=650  \4$aMedicina.
=780  00$aEs continuaci{dbldotb}n de. $t"Journal of Medical Education" $xISSN 0022-2577
=856  \\$uhttp://ovidsp.ovid.com/ovidweb.cgi?T=JS&MODE=ovid&NEWS=n&PAGE=toc&D=ovft&AN=00001888-000000000-00000   $zAcceso al texto completo
=952 \\$aBNCS-CH\\$bBNCS-CH\\$h1989\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL

=LDR  00901nas  2200205 i 4500
=005  20061017111721.0
=008  920528d19721998sp\br\p\r\\\\\0\\\a\spa\d
=022  0\$a0300-5062
=041  0\$aspa
=210  0\$aActas Luso Esp Neurol Psiquiatr Cienc Afines
=245  00$aActas Luso Espa{ogon}olas de Neurolog{rcommaa}a, Psiquiatr{rcommaa}a y Ciencias Afines /$cGrupo para el progreso de la Psiquiatria.
=260  \\$aMadrid : $bGarsi, $c1972-1998.
=270  \\$aLondres 17. 28028 Madrid
=300  \\$c26 cm.
=310  \\$aBimensual
=525  \\$aTiene como suplemento: "Actas Luso Espa{ogon}olas de Neurolog{rcommaa}a, Psiquiatr{rcommaa}a y Ciencias Afines. Suplemento", ISSN, 1137-604X.
=650  14$aPsiquiatr{rcommaa}a.
=780  00$aEs continuaci{dbldotb}n de. $tActas luso-espa{ogon}olas de neurolog{rcommaa}a y psiquiatr{rcommaa}a$xISSN 0001-7329
=785  00$cContinuada por$tActas Espa{ogon}olas de Psiquiatr{rcommaa}a $xISSN 1139-9287
=952 \\$aBNCS-CH\\$bBNCS-CH\\$h(1988-1989)1990-91(1992)1993(1994)1995-97(1998).\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL

=LDR  00558nas  2200169 i 4500
=005  20110317114649.0
=008  920528c1949\\\\spamr\p\\\\\\\0\\\\\spa\d
=022  0\$a0001-6519
=041  1\$aspa
=210  1\$aActa Otorrinolaringol Esp
=245  00$aActa otorrinolaringol{dbldotb}gica espa{ogon}ola / $cSociedad Espa{ogon}ola de Otorrinolaringolog{rcommaa}a y Patologia C{caron}rvico-Facial.
=260  \\$aMadrid : $bGarsi, $c1949.
=270  \\$aC/ Londres, 17 28028 Madrid
=300  \\$c27 cm.
=310  \\$aBimestral
=650  \4$aMedicina-$xEspecialidades.
=952 \\$aBNCS-CH\\$bBNCS-CH\\$h(1989-90)1991-97(1998),1999-2006.\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL

=LDR  00503nas  2200181 i 4500
=005  20030814120145.0
=008  920528d1984\\\\sp\mr\pr\\\\\\0\1\a\spa\d
=022  0\$a0213-0580
=041  1\$aspa
=210  1\$aActa Paediatr Scand (Ed Esp)
=245  00$aActa paediatrica scandinavica / $cSaned.
=250  \\$aEdicion en espa{ogon}ol.
=260  \\$aMadrid : $bSANED, $c1984.
=270  \\$aApolonio Morales, 6. 28036 Madrid
=300  \\$c27 cm.
=310  \\$aBimestral
=650  \4$aPediatr{rcommaa}a.
=952 \\$aBNCS-CH\\$bBNCS-CH\\$h1984-86,(1991-92).\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL

=LDR  00627nas  2200181 i 4500
=005  20110317121830.0
=008  920528c1945\\\\sp\mr\p\p\\\\\0\\\\\spa\d
=022  0\$a0001-6640
=041  0\$aspa
=210  1\$aActa Pediatr Esp
=245  10$aActa pedi{grave}trica espa{ogon}ola / $cSaned.
=260  \\$aMadrid : $bSaned, $c1945-
=270  \\$aApolonio Morales, 6.28036 Madrid
=300  \\$c26 cm.
=310  \\$aMensual
=650  \4$aPediatr{rcommaa}a.
=780  00$aEs continuaci{dbldotb}n de. $tActa pedi{grave}trica (Madrid), ISSN 0301-5203
=952 \\$aBNCS-CH\\$bBNCS-CH\\$h(1945),(1948-49),(1951-52),(1955),(1964),(1967-68),1970-77(1978)1979-82(1983-87)1988-93(1994)1995-96(1997-98)1999-2010.\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL

=LDR  00445nas  2200169 i 4500
=005  20030814120318.0
=008  920528c1958\\\\sp\sr\p\\\\\\\0\\\\\spa\d
=022  0\$a0011-7655
=041  0\$aspa
=210  1\$aActual Econ
=245  10$aActualidad econ{dbldotb}mica / $cPunto Editorial.
=260  \\$aMadrid : $bPunto Editorial, $c1958.
=270  \\$aP{eth} Recoletos,1. 18001 Madrid
=300  \\$c27 cm.
=310  \\$aSemanal
=650  \4$aEconom{rcommaa}a.
=952 \\$aBNCS-CH\\$bBNCS-CH\\$h(1985-94).\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL

=LDR  00798nas  2200181 i 4500
=005  20091124134137.0
=008  920528c1973\\\\sp\br\p\\\\\\\0\11a\mul\d
=022  0\$a0301-0546
=041  1\$amul
=210  1\$aAllergol Immunopathol (Madr)
=245  00$aAllergologia et immunopathologia / $cSociedad Espa{ogon}ola de Alergia e Inmunolog{rcommaa}a Cl{rcommaa}nica ; Sociedad Latinoamericana de Alergia e Inmunolog{rcommaa}a ; International Association of Asthmology ; Asociaci{dbldotb}n de Inmunolog{rcommaa}a Clinica y Alergolog{rcommaa}a Pediatrica.
=260  \\$aBarcelona : $bDoyma, $c1973.
=300  \\$c27 cm.
=310  \\$aBimestral
=525  \\$aTiene como suplemento: Allergolog{rcommaa}a et Immunopatholog{rcommaa}a. Supllementum, ISSN 0211-6448.
=650  \4$aMedicina-$xEspecialidades.
=952 \\$aBNCS-CH\\$bBNCS-CH\\$h(1988)1989(1990-91)1992-98(1999)2003-\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL
=952 \\$aBNCS-C.UNIV\\$bBNCS-C.UNIV\\$h1974-77.\\$oBNCS-C.UNIV0000001\\$pBNCS-C.UNIV0000001\\$yJNL

=LDR  00782nas  2200205 i 4500
=005  20110125160214.0
=008  920528c1974\\\\-usqr\p\r\\\\\0\\\a\eng\d
=022  0\$a0095-2990
=022  \\$a1097-9891 (online)
=041  0\$aeng
=210  0\$aAm J Drug Alcohol Abuse
=245  00$aAmerican journal of drug alcohol abuse / $cThe American Academy of Psychiatrists in Alcoholism & Addictions.
=260  \\$aNew York : $bMarcel Dekker, $c1974.
=270  \\$a270 Madison Avenue, New York 10016
=300  \\$c25 cm.
=310  \\$aTrimestral
=530  \\$aDisponible en versi{dbldotb}n electr{dbldotb}nica  1999-2008.
=650  \4$aDependencia a sustancias nocivas.
=856  \\$uhttps://www.swetswise.com/eAccess/viewTitleIssues.do?titleID=9055&year=2008   $zAcceso al texto completo
=952 \\$aBNCS-CH1989-96,1998-2008.\\$bBNCS-CH1989-96,1998-2008.\\$h\\$oBNCS-CH1989-96,1998-2008.0000001\\$pBNCS-CH1989-96,1998-2008.0000001\\$yJNL

=LDR  00943nas  2200241 i 4500
=005  20110318131920.0
=008  920528c1965\\\\-usqr\p\r\\\\\0\\\\\eng\d
=022  0\$a0002-9262
=022  \\$a1476-6256 (online)
=041  0\$aeng
=210  1\$aAm J Epidemiol
=245  00$aAmerican Journal of Epidemiology / $cSchool of Hygiene and Public Health of The Johns Hopkins University.
=260  \\$aBaltimore : $bAmerican Journal of Epidemiology, $c1965.
=270  \\$a624 N.Broadway, Room 225
=300  \\$c23 cm.
=310  \\$aMensual
=530  \\$aDisponible en versi{dbldotb}n electr{dbldotb}nica desde 1996.
=650  \4$aEpidemiolog{rcommaa}a.
=780  00$aEs continuaci{dbldotb}n de. $tAmerican Journal of Hygiene $xISSN 0096-5294
=856  \\$uhttp://aje.oxfordjournals.org/?code=aje&.cgifields=code $zAcceso al texto completo
=952 \\$aBNCS-CH\\$bBNCS-CH\\$h1971-75(1976)1977-2003(2004)2005-\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL
=952 \\$aBNCS-C.UNIV\\$bBNCS-C.UNIV\\$h1990-93(1994)1995-2001.\\$oBNCS-C.UNIV0000001\\$pBNCS-C.UNIV0000001\\$yJNL
=952 \\$aBNCS-MAJ\\$bBNCS-MAJ\\$h1965-75(1976-77)1978-94(1995).\\$oBNCS-MAJ0000001\\$pBNCS-MAJ0000001\\$yJNL

The final result have to be the same but the field =856 must be like this (I just paste here the part)

Code:
=650  \4$aMedicina.
=780  00$aEs continuaci{dbldotb}n de. $t"Journal of Medical Education" $xISSN 0022-2577
=856  \\$aBNCS-CH\\$bBNCS-CH\\$h1989\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL $yEJNL
=952 \\$aBNCS-CH\\$bBNCS-CH\\$h1989\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL

With the current script, there is a =952 filed duplicated into the =856 code..This is the problem.
Hope consistent this time
# 4  
Old 09-25-2011
Woops. I must've deleted my post while you were writing that response. I apologize for that.

After posting, I noticed that the data wasn't necessarily inconsistent (if one assumes that the input is space delimited and that the =952 line in the input of post #3 consists of a single column).

As far as I can tell, I can't undelete the post to restore my part in the thread.

The least I can do is try to help you out. Smilie

Reading your response now...

... sorry, but I'm not quite sure what to make of it. I'll give it another look later in the day.

Regards and good luck,
Alister

Last edited by alister; 09-25-2011 at 01:43 PM..
# 5  
Old 09-25-2011
Several points,

- In the first post the sample input data is different from your second post. In the first post, line beginning with '=952' has string separated by spaces, but not in your second post.

- In you second post you indicate that output should be something like:
Code:
=856  \\$aBNCS-CH\\$bBNCS-CH\\$h1989\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL $yEJNL 
=952 \\$aBNCS-CH\\$bBNCS-CH\\$h1989\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL

while in your first post you indicate to add '$yEJNL' after the second field. However in this example appears at the end. Which is correct?

- Finally, in the first post you indicate to add the last two fields of line '=952' in line '=856', however in the second post you add more fields besides these two.

In short, perhaps I misunderstood your question but I am very confused with your examples. If you change data and specifications it is obvious that my script won't work.

Regards,
Birei
# 6  
Old 09-26-2011
Hi

this script is 80% good:

Code:
use warnings; use strict;  while ( <> ) {         next if m/\A=856/;         chomp;          if ( m/\A=952/ ) {                 my @f = split;                 printf "=856  %s\n%s\n",                          join( q[\\\\], $f[1] . qq[ ] . $f[2] . q[$yEJNL], $f[$#f-1], $f[$#f] ),                         $_;                  next;         }          printf "%s\n", $_; }

The final result should the same for =856 but without the =952 code in.
So =856 at the end become just:

=856 \\$aBNCS-CH\\$bBNCS-CH\\$h1989\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yEJNL
Hope you can help today with that.
Thanks a lot

Cheers
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find and replace?

Hi All, I have data like below 1 CREATE TABLE temp123 2 ( 3 col1 INTEGER, 4 col2 CHAR(3) CHARACTER SET LATIN NOT CASESPECIFIC, 5 col3 DECIMAL(19,0), 6 col4 VARCHAR(80) CHARACTER SET LATIN NOT CASESPECIFIC, 7 start_dt DAte FORMAT 'YY/MM/DD', 8 end_dt DATE FORMAT 'YY/MM/DD', 9 datecol1... (6 Replies)
Discussion started by: baranisachin
6 Replies

2. Shell Programming and Scripting

Find and Replace

i am having a file test1.txt and its contents is as follows. <abcaaa bbb ccc ddd> <dddeeeffff> <my computer> <abcmydocuments> Now I need to find the text abc and should be replaced as follows. <abc> <dddeeeffff> <my computer> <abc> First line has the text "abc" and it has to be... (3 Replies)
Discussion started by: kmanivan82
3 Replies

3. Shell Programming and Scripting

Find/Replace

I have the following requirement in the shell script 1. I have more than 200 shell script files. I need to find out how many shell scripts have "sqlplus /" in the shell file 2. I need to replace all the shell scripts in the single command for example: connect scott/scott replace as ... (6 Replies)
Discussion started by: pmsuper
6 Replies

4. Solaris

find/replace?

Dear All To find a file, according to you, I tried as: #find / -name file-name -print To find a string inside the files , I tried as : #find / -name "*" |xargs grep "string" Can you please let me know how can I try for find/replace (i.e. finding the intended string inside the text files... (6 Replies)
Discussion started by: hadimotamedi
6 Replies

5. Shell Programming and Scripting

Find Replace

Need to convert echo "7 6" to $7,$6 But the count of numbers can increase say echo "7,6,8,9" tried this didn't work echo "7 6" | sed 's/\(*\)/\1/' But did not help much (3 Replies)
Discussion started by: dinjo_jo
3 Replies

6. UNIX for Dummies Questions & Answers

find and replace

I am looking to find and replace a string in a file, can anyone suggest a global find and replace. looked at previous replies on other queries but none seem to address what i am looking for. aint familiar with sed so trying to use ordinary unix commands if possible Thanks in advance (2 Replies)
Discussion started by: SummitElse
2 Replies

7. Shell Programming and Scripting

find and replace

hi, i have a data in a file like below: 100 8388kmn844., 8488 200 8398kmn894., 8398 i want replace from kmn to . as null. output should be 100 8388, 8488 200 8398, 8398 Plz help. Thanks in advance (1 Reply)
Discussion started by: javeed7
1 Replies

8. Shell Programming and Scripting

find and replace

Hi, There are some "n" files in a directory which contains comman string.A command to find and replace the string in all the files without looping. like if i am in a directory : # find ./ -name ".txt" | xargs sed -e 's/test/tst' Upto here is performed correctly and i want to... (4 Replies)
Discussion started by: rakshit
4 Replies

9. UNIX for Advanced & Expert Users

Please help with find and replace:

Hi I am trying to find a product code hightlighted in red, and re-insert it at another place on the same file. I shall be grateful if anyone can help me with this. Stuck and have deadline!!:confused: Original Line: (I can get source data in one of these two formats) ISD=977155185403901+DIE... (2 Replies)
Discussion started by: gloovy_tb
2 Replies

10. UNIX for Dummies Questions & Answers

find and replace

I have statement like this column_id.columnname=="value" in unix i want to modify above statement to variable1=="value" that means i have to replace the string before "==" by string "variable1" second catch is, in statement instead of "==" you can have any arithmatic comarision... (7 Replies)
Discussion started by: mahabunta
7 Replies
Login or Register to Ask a Question