What I would like to do is just get the records where the field =590 is eq to \\$aEn Curs
as in the exemple, and from this condition get an other filed and put it into a csv file..for exemple I need the =001 field and the =025
=001 vtls000000013
So the csv should be:
vtls000000013;14
Is it possible to do with sed? I try the first filter with this, but I have errors:
Whassshh yes it works.
Many thanks,,, But how does it work?
I see 3 parts in you script.
the 2 first are the field I want to catch and join...ok and the last one is the filter condition. But I'm not abble to see more
But .. it's ok I can use this script ..If I want to catch other field I just have to change the code I guess, I'll try
Thans and have a nice week end
---------- Post updated at 11:38 AM ---------- Previous update was at 11:35 AM ----------
Hi,
I change single quote with " and the script works:
Regarding the sed script: The first is put in the hold buffer ( h ) and the second is appended to the hold buffer ( H ). It the 590 field is correct the hold buffer is retrieved ( g ), the linefeed ( \n ) is replaced by a semicolon and the result is printed..
That has to do with the changed order of sample fields. This gets a bit too complicated for sed, perhaps you could try if awk might be a better choice:
awk '
{
i=$1
sub(i " *",x)
A=A(A?"-":x) $0
}
i=="=310"{
if (A["=590"]~/\$aEn Curs/) print A["=001"],A["=310"],A["=037"],A["=050"],A["=099"]
for(i in A) delete A
}
' OFS=\; file
---------- Post updated 01-20-13 at 05:02 AM ---------- Previous update was 01-19-13 at 12:22 PM ----------
Hello
ok I found the problem, but I don't know how to fix it with the awk script.
The problem happend when one of the field in the list do NOT exists into the bib.mrk file:
Exemple =310
I can see that adding =310 manually to the bib.mrk file, this record is created properly into the csv output file.
Can you modify the awk script in order to get this probability ?
Some fields in the list can NOT be present.
awk '
function pr(){ # define the print array elements function
if (A["=590"]~/\$aEn Curs/) print A["=001"],A["=310"],A["=037"],A["=050"],A["=099"] # Print the array elements
for(i in A) delete A # Delete the array elements
}
{
i=$1 # i becomes the index in field $1
sub(i " *",x) # delete the index and spaces following it from the line
A=A(A?"-":x) $0 # add the line to the array element with index "i" and insert a "-" when there is already an entry present
}
!NF{ # if there is an empty line then
pr() # print array elements
}
END{ # if there are no more records
pr() # print array elements
}
' OFS=\; bib.mrk # set the Output Field Separator to ";"