Manipulating data per paragraph
I'm still pretty novice to bash, but I have some experience in manipulating data per line by using the 'while read' structure and for example extracting some data with awk and such.
Now I have an ldif file, which has data in it per paragraph (separated by a newline). Now I want to extract data from it (different attributes in it) per ldif record, which is harder cause there is no 'read paragraph' of course. :)
Example, if I have an ldif file like this:
I want to be able to do checks and compares of attributes in every record, like comparing time and modifyTimestamp, but I need to do it in all of the records (skip none) and I would like it generic enough so I'm able to use it in a for or while loop and, say, grep the data out of it.
I'm sure there are cool solutions for this in sed or awk and I hope I can learn from it how it's done and I can try to use it to my own liking.
Thanks in advance!
Well using awk you can set the record separator and that will then make each paragraph a record. You will then need to choose whether you want to split the data or use
the field separator ... it will depend on how uniform your data is. As a demo:
Depends how complex these checks are, but I'd seriously consider using Perl; its very good at this sort of thing.
Thanks all for replying.
grail: the awk option sounds quite useful but now I need to figure out how to get data out of it on a per record basis. So how would I use awk to enter a sort of while or for loop (or split it so I can do stuff on each record individually) and grab the time and modifyTimestamp attributes from each record?
chrism01: thanks for the tip but I suck even more at perl than I suck at bash ;)
Here is my bible. Have a look at field separators and the split function.
|All times are GMT -5. The time now is 03:04 PM.|